Forum Discussion

GradyJr's avatar
GradyJr
Contributor
5 years ago
Solved

using SendEmail function

I  am able to build and send an email in TestCoomplete using the SendEmail function but it appears that the only type of email is Plain Text. Is there a way to create html emails so I can embed hyperlinks in the body?

  • In the Help Topic, "Sending Email From Scripts", there are three sections. I was able to resolve my problem by using the third option "Via Microsoft Outlook" I have to be sure to close my Outlook session before I leave each evening but my script can build an HTML body and then send it using code similar to the following example.

     

    dim outlook
    Set outlook = Sys.OleObject("Outlook.Application")
    dim body
    body = "<html xmlns:v=""urn:schemas-microsoft-com:vml"" xmlns:o=""urn:schemas-microsoft-com:office:office"" xmlns:w=""urn:schemas-microsoft-com:office:word"" xmlns:m=""http://schemas.microsoft.com/office/2004/12/omml"" xmlns=""http://www.w3.org/TR/REC-html40"">"
    body = body + "<head>"
    body = body + "<META HTTP-EQUIV=""Content-Type"" CONTENT=""text/html; charset=us-ascii"">"
    body = body + "<meta name=Generator content=""Microsoft Word 15 (filtered medium)"">"
    body = body + "</head>"
    body = body + "<body lang=EN-US link=""#0563C1"" vlink=""#954F72"">"
    body = body + "<div>"
    body = body + "<....a lot more html tags including  <a href=""file://filename.ext"">Link Text</a>.....>"
    body = body + "</div></body></html>"
    Dim mi
    Set mi = outlook.CreateItem(0)
    mi.BodyFormat = olFormatHTML
    mi.Subject = "Test Results"
    mi.HTMLBody = body
    mi.To = "recipients.name@companyname.com"
    mi.Send
    outlook.Quit

4 Replies

    • GradyJr's avatar
      GradyJr
      Contributor

      In the Help Topic, "Sending Email From Scripts", there are three sections. I was able to resolve my problem by using the third option "Via Microsoft Outlook" I have to be sure to close my Outlook session before I leave each evening but my script can build an HTML body and then send it using code similar to the following example.

       

      dim outlook
      Set outlook = Sys.OleObject("Outlook.Application")
      dim body
      body = "<html xmlns:v=""urn:schemas-microsoft-com:vml"" xmlns:o=""urn:schemas-microsoft-com:office:office"" xmlns:w=""urn:schemas-microsoft-com:office:word"" xmlns:m=""http://schemas.microsoft.com/office/2004/12/omml"" xmlns=""http://www.w3.org/TR/REC-html40"">"
      body = body + "<head>"
      body = body + "<META HTTP-EQUIV=""Content-Type"" CONTENT=""text/html; charset=us-ascii"">"
      body = body + "<meta name=Generator content=""Microsoft Word 15 (filtered medium)"">"
      body = body + "</head>"
      body = body + "<body lang=EN-US link=""#0563C1"" vlink=""#954F72"">"
      body = body + "<div>"
      body = body + "<....a lot more html tags including  <a href=""file://filename.ext"">Link Text</a>.....>"
      body = body + "</div></body></html>"
      Dim mi
      Set mi = outlook.CreateItem(0)
      mi.BodyFormat = olFormatHTML
      mi.Subject = "Test Results"
      mi.HTMLBody = body
      mi.To = "recipients.name@companyname.com"
      mi.Send
      outlook.Quit

      • TanyaYatskovska's avatar
        TanyaYatskovska
        SmartBear Alumni (Retired)

        Happy to hear that the issue was resolved!

        Happy testing :)

    • TanyaYatskovska's avatar
      TanyaYatskovska
      SmartBear Alumni (Retired)

      Hi GradyJr,

       

      It's great to hear the issue was resolved. Could you please share the solution with us? It will help community members in the future.