Could not send an email via SendMail Function in TestComplete
The detail of the function is as follows:
SendMail(ToAddress, FromHost, FromName, FromAddress, Subject, Body, FileName1, FileName2, ...)
After replace the parameters with the arguments, the function becomes:
SendMail ("kying@palantirsolutions.com", "mail.palantirsolutions.com", "Kai", "kying@palantirsolutions.com", "DataFlow automation testing Result", )
Previously, this function was working. But now when I run this function, it gives me the error message: Unable to send email to the mail.palantirsolutions.com server.
And in additional information: Error message: "5.7.1 Client was not authenticated
So I reckon that I send the request of sending email to the server, but my user name is not in the authenticated user list, so I am prohibited to send email. Is my reckon correct, or there is another cause of the issue
Cheers.
Kai
- Since you need to be able to specify a port and, potentially, authenticate the user that you need to use to send the e-mail, you might want to consider using the CDO objects to send the e-mail. You can find the article describing this method here. It contains examples as to how to create the routine in order to do what you're asking.
It does sound like, based upon the responses and functionality, that your problem is due to authentication on the server. Let me know if CDO helps or if you need additional help. Hi,
I have worked on the script, and it works now. For both gmail and outlook.com
Entering user name/password fails to send the mails so I deleted these lines. Apparently no authentication or whatever is needed.
Here is the working code , including server names for Outlook and gmail:
Outlook.com:
Function Send_Email_using_Outlook(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") = "smtp-mail.outlook.com" ' SMTP server
mConfig.Fields.Item(schema + "smtpserverport") = 25 ' Port number
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 "E-mail cannot be sent", Err.Description
SendEMail = False
Else
Log.Message "Message to <" + mTo + "> was successfully sent"
SendEMail = True
End If
End Function
GMAIL:
Function Send_Email_using_GMail(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") = "smtp.gmail.com" ' SMTP server
mConfig.Fields.Item(schema + "smtpserverport") = 25 ' Port number
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 "E-mail cannot be sent", Err.Description
SendEMail = False
Else
Log.Message "Message to <" + mTo + "> was successfully sent"
SendEMail = True
End If
End Function
If you call these functions using KDT testing enter From/To/subject/body and Path to attach files:
Hope this helps you. I will also inform support on this.
Regards,
Mathijs