Forum Discussion

mesg2anil's avatar
mesg2anil
Regular Contributor
12 years ago

Sending EMail Through Script

Hi,



Below is the script written to send an email through script, but I'm not getting any email... any suggestions here please?



Sub MainTest

  If SendEmail("anil.yadrami@in4velocity.com", "anil.yadrami@in4velocity.com", "Subject", _

             "Message body", "E:\Anil-Backup\Test Complete\Projects_Old\In4Suite Project\TC_Command_Line.txt") Then

    ' Message was sent

    Log.Message "sent"

  Else

    ' Message was not sent

    Log.Message "not sent"

  End If

End Sub



'This function is called above

Function SendEmail(mFrom, mTo, mSubject, mBody, mAttachment)


  Err.Clear

  On Error Resume Next


  schema = "http://webmail.in4velocity.com/"

  Set mConfig = Sys.OleObject("CDO.Configuration")

'  mConfig.Fields.Item(schema + "sendusing") = 587 ' cdoSendUsingPort  'commented this, dont know what exactly this do

  mConfig.Fields.Item(schema + "smtpserver") = "smtp.gmail.com" ' SMTP server

  mConfig.Fields.Item(schema + "smtpserverport") = 587 ' Port number

  mConfig.Fields.Item(schema + "sendusername") = "anil" ' User name (if needed)

  mConfig.Fields.Item(schema + "sendpassword") = "Pwd123456" ' User password (if needed)

  mConfig.Fields.Update()


  Set mMessage = Sys.OleObject("CDO.Message")

  mMessage.Configuration = mConfig

  mMessage.From = "anil.yadrami@in4velocity.com"

  mMessage.To = "anil.yadrami@in4velocity.com"

  mMessage.Subject = "Automation: Testing"

  mMessage.HTMLBody = "Email Received"


  aqString.ListSeparator = ","

  For i = 0 To aqString.GetListLength(mAttachment) - 1

    mMessage.AddAttachment aqString.GetListItem(mAttachment, i)

  Next


  mMessage.Send


  If Err.Number > 0 Then

    Log.Error "E-mail cannot be sent", Err.Description

    SendEMail = False

  Else

    Log.Message "Message to <" + mTo + "> was successfully sent"

    SendEMail = True

  End If

End Function

12 Replies