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

  • Hi,


    Do I need to login to my email account through IE and keep it open?


    No, this isn't needed.


    In the script sendusing is = 2 "mConfig.Fields.Item(schema + "sendusing") = 2 ' cdoSendUsingPort" I'm using this line as it is, do I need to change it?


    The sendusing field specifies the method used to send messages. "2" means that the message should be sent via the network. Go through  this MSDN section to get detailed information on configuring the CDO scheme.


    should this file be of any format


    According to the MSDN description of the CDO.Message.AddAttachment method, you can add any type of attachment to a message.


    do I need to mention this anywhere in the script


    No, you needn't.


    A few more things to try:

    * Use port 25 or 465 (not 587).

    * If your Google Apps domain uses 2-step verification, you may need to generate an application-specific password for your account and use that password in your script instead of the Google Apps account password.


    Finally, I'd like to note that the CDO (Collaboration Data Objects) library used in your script is developed and maintained by Microsoft, and we don't provide technical support for third-party scripting objects. So, I recommend troubleshooting this issue with your system administrator and a Google Apps administrator, on MSDN Forums or Stack Overflow. You'll more likely get an answer there. In addition to that, you can find troubleshooting tips using Google search for cdo "google apps".


    Good luck!


    Ann

    • k_cnureddy's avatar
      k_cnureddy
      New Contributor

      Hi, Can someone help me in reading or verifying the received emails using Collaboration Data Object (CDO).

       

      Thank you,

      Srini