Forum Discussion

RajTC's avatar
RajTC
Occasional Contributor
9 years ago

Sending Email with attachment from script is just forwarding another system generated email

Hi,

 

I am saving the log file( in .mht format) in a folder after execution completes and sending email with attachment.

 

But the email I received contains another forwarded email and not able to open the attached results log file. When I check the sent email folder, It is displaying as forwarded message.

 

Please see the screenshot.

 

 

 

6 Replies

  • You haven't said how you are sending the mail. (There are several ways you can generate mail with TestComplete)

     

    You haven't said which scripting language you're using.

     

    You haven't posted any code snippets, or details of any errors or anything unexpected in your log files.

     

    All you have said is "it isn't sending what I expected". I'm not sure what you're hoping to hear in reply. You might want to post a little more detail.

    • RajTC's avatar
      RajTC
      Occasional Contributor

      Hi Colin,

       

      No errors, Email was sent successfully but with the format showed in the screenshot.

       

      I couldn't able to find the attachment in the received mail.

       

      Please find the code below which I was used.

       

       

      Function SendEmailResults(mFrom, mTo, mSubject, mBody, mAttachment)
      Dim smtpServer, smtpPort, userLogin, userPassword
      Dim authenticationType, useSSL, connectionTimeout
      Dim schema, mConfig, mMessage

      smtpServer = "smtp.gmail.com"
      smtpPort = 25
      userLogin = "******" ' e.g. "abc" if the address is abc@gmail.com
      userPassword = "******"
      authenticationType = 1 ' cdoBasic
      connectionTimeout = 30
      ' Required by Gmail
      useSSL = True

      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") = smtpServer
      mConfig.Fields.Item(schema & "smtpserverport") = smtpPort
      mConfig.Fields.Item(schema & "sendusername") = userLogin
      mConfig.Fields.Item(schema & "sendpassword") = userPassword
      mConfig.Fields.Item(schema & "smtpauthenticate") = authenticationType
      mConfig.Fields.Item(schema & "smtpusessl") = useSSL
      mConfig.Fields.Item(schema & "smtpconnectiontimeout") = connectionTimeout
      mConfig.Fields.Update()

      Set mMessage = Sys.OleObject("CDO.Message")
      Set mMessage.Configuration = mConfig
      mMessage.From = mFrom
      mMessage.To = mTo
      mMessage.Subject = mSubject
      mMessage.HTMLBody = mBody

      If 0 < Len(mAttachment) Then
      mMessage.AddAttachment(mAttachment)
      End If

      mMessage.Send()

      If Err.Number > 0 Then
      Call Log.Error("E-mail cannot be sent", Err.Description)
      SendEMail = False
      Err.Clear()
      Else
      Log.Message("Message to <" & mTo & "> was successfully sent")
      SendEMail = True
      End If
      End Function

      • Colin_McCrae's avatar
        Colin_McCrae
        Community Hero

        Hmmm. I use CDO to send mail via script and it works fine.

         

        BUT .... I'm using our internal SMTP server, not Gmail. It may be a Gmail thing why they come through as forwarded. I got a mail sent to me via script overnight last night and it came through as a normal e-mail. Same as always. Attachments were present and correct.

         

        One thing that does jump out at me:

         


        RajTC wrote:


        If 0 < Len(mAttachment) Then
        mMessage.AddAttachment(mAttachment)
        End If


         

        What are you sending it?

         

        Attachments are supposed to be file paths (so it can find the relevant file to attach to the mail). Are you giving it a valid file path?

         

        As per: https://support.smartbear.com/testcomplete/docs/scripting/sending-email-from-scripts.html#CDO

         

        If you are using a modified version of the example code in the above link (I suspect you are), it normally uses a list. You're not treating it as a list so I presume are sending a single, valid (hopefully!) file path + name instead?