dennis1
8 years agoOccasional Contributor
Send email function does not work as expected
Hi,
I used a function from the TestComplete documentation and filled in the desired values.
According to the test log it did what it was supposed to do but the mail has not been sent.
I'm kind of new to this so most likely made a dumb mistake..
Hope someone can help me out.
Thanks!
source of function:
https://support.smartbear.com/testcomplete/docs/scripting/sending-email-from-scripts.html
Function SendEmail(mFrom, mTo, mSubject, mBody, mAttachment)
Dim i, schema, mConfig, mMessage
Err.Clear
On Error Resume Next
schema = "http://schemas.microsoft.com/cdo/configuration/"
Set mConfig = Sys.OleObject("CDO.Configuration")
mConfig.Fields.Item(schema + "sendusing") = 2 ' cdoSendUsingPort
mConfig.Fields.Item(schema + "smtpserver") = "ServerName" ' SMTP server
mConfig.Fields.Item(schema + "smtpserverport") = 25 ' Port number (standard)
' If you use Gmail --
mConfig.Fields.Item(schema + "smtpserver") = "smtp.gmail.com"
mConfig.Fields.Item(schema + "smtpserverport") = 465 'port number (suggested online)
' If you use Outlook --
' mConfig.Fields.Item(schema + "smtpserver") = "smtp-mail.outlook.com"
' mConfig.Fields.Item(schema + "smtpserverport") = 25
mConfig.Fields.Item(schema + "smtpauthenticate") = 1 ' Authentication mechanism
mConfig.Fields.Item(schema + "Example1@gmail.com") = "" ' User name (if needed)
mConfig.Fields.Item(schema + "Password") = "" ' User password (if needed)
mConfig.Fields.Update
Set mMessage = Sys.OleObject("CDO.Message")
mMessage.Configuration = mConfig
mMessage.From = mFrom
mMessage.To = mTo
mMessage.Subject = mSubject
mMessage.HTMLBody = mBody
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 "Email cannot be sent", Err.Description
SendEMail = False
Else
Log.Message "Message to <" + mTo + "> was successfully sent"
SendEMail = True
End If
End Function
Sub MainTest
If SendEmail("Example2@gmail.com", "Example1@gmail.com", "Subject", _
"Message body","C:\Users\Therapy\Pictures") Then
Log.Message "Message was sent"
Else
Log.Message "Message was not sent"
End If
End Sub