Forum Discussion

yingkai1208's avatar
yingkai1208
Contributor
11 years ago

Could not send an email via SendMail Function in TestComplete

Hi

 

The detail of the function is as follows:

 

SendMail(ToAddressFromHostFromNameFromAddressSubjectBodyFileName1FileName2, ...)

 

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

     

     

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    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.
    • mgroen2's avatar
      mgroen2
      Super Contributor

      tristaanogre

       

      I have copied the code from the example here, and when I run the test the message in the log says "mail is succesfully sent", however no emails arrive. Not in spambox either. I am testing it with Outlook smtp server smtp-mail.outlook.com but don't have a clue which port to use, and which authentication mechanism to use. 

      I only get a message back in the log saying the mail is succesfully sent but no mails are arriving..

       

      Do you have any tips?

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor
        Most of the time, SMTP servers use port 25 but I know that there are a variety of configurations and settings. So, you would need to know the settings for your e-mail server.

        The message you're getting from the log is what is written out by the code... it essentially says that the code executed successfully but doesn't actually have any relation to whether or not the ACTUAL e-mail got sent. I'm guessing that, since you don't know the settings for the client, the code completed, but nothing sent.

        Since you're using Outlook.com, I went ahead and looked it up.

        http://windows.microsoft.com/en-US/windows/outlook/send-receive-from-app

        In short, you're going to use port 25, you're going to have an authenticate method (set to 1), you're e-mail address is your user name and the password you use for the outlook.com account is your password.

        Hope this helps!

        Suggestion: Since this particular thread was marked as "solved", it might be better to start a new thread to debug this particular situation.
  • Further to the thread. Is there a way to specify port of the server in the function SendMail?



    Since in the past few days. the function SendMail does not work, I ask it support in my company about that. They replied me that the exchange server is working fine for my account. And the only change ever made the the port numer.



    So I try to use SendEmail (which could specify port number) to replace SendMail. The weird thing is, I changed configurations (smtpServer, port number, userLogin and userPassword) to the ones in my company, although SendEmail tells me the email is sent successfully, I could not receive the email. The function only works when I use gamil as the sender and server.



    Back to the function SendMail, for some unknown reason, this function works again today. I doubt there was some change made in server exchange. (on port)