Ask a Question

Sending EMail Through Script

Regular Contributor

Sending EMail Through Script


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("", "", "Subject", _

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

    ' Message was sent

    Log.Message "sent"


    ' Message was not sent

    Log.Message "not sent"

  End If

End Sub

'This function is called above

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


  On Error Resume Next

  schema = ""

  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 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)


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

  mMessage.Configuration = mConfig

  mMessage.From = ""

  mMessage.To = ""

  mMessage.Subject = "Automation: Testing"

  mMessage.HTMLBody = "Email Received"

  aqString.ListSeparator = ","

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

    mMessage.AddAttachment aqString.GetListItem(mAttachment, i)



  If Err.Number > 0 Then

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

    SendEMail = False


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

    SendEMail = True

  End If

End Function

Regular Contributor

Hi Ann,

There is nothing displayed in Additional Details section in the log. The script is passing but I dont get any email. I've few doubts, please let me know...

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

2. 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?

3. We are using gmail for office internal email, the link will be, do I need to mention this anywhere in the script? Our gmail is configured to MS-outlook, do you think of any other settings?

4. In SendEmail, I'm giving "c:\Hello.txt", should this file be of any format or for testing purpose I can pass any file as below...?

If SendEmail("", "", "Automation: Script Email", "Automation Message body", "c:\Hello.txt") Then

SendEmail("", "", "Automation: Script Email", "Automation Message body", "c:\Hello.txt")


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!


I’m not a member of the SmartBear Support Team, I’m just helping users in this community.
Any views or opinions expressed do not necessarily represent those of SmartBear Software.

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


Thank you,


Showing results for 
Search instead for 
Did you mean: