Forum Discussion

marin's avatar
marin
Frequent Contributor
13 years ago

How to include a hyperlink into eMail message body

Hello all,



in my project I am using SendMail() mtehod to notify recipients about test results.

What I'd like to achieve is to include a hyperlink pointing to corresponding generated  .mht file into eMail body rather than attaching the whole .mht file.

I noticed that eMail generated via SendMail() method is formatted as plain text - therefore a hyperlink will not work there.



Is there a possibility to format the eMail as HTML and thus be able to include a hyperlink into eMail body?



Many thanks for any hints.



Marin
  • Hello Marin,



    I just saw your post, sorry if it's too late!



    You can check this article from Smartbear to send emails from scripts.



    Take a look at 'Sending E-Mail Using CDO' section, which lets you send html code inside your emails.



    Hope it helped!
  • marin's avatar
    marin
    Frequent Contributor
    Hello Javier,



    many thanks for your suggestion, much appreciated.

    I was hoping that there would be an option to use HTML format within the built in SendMail() function, but apparently there isn't.



    I resolved the issue by using CDO. It took me some tome to figure out the correct parameters for Exchange but now I've got this working solution:




    function SendCDOEmail(testResult,result,file)

    {

      var schema, mConfig, mMessage, mSubject, mBody, mTo;

     

      mBody="Status:\r\n"+ result +"\r\nLog file: <a href =\"" + file + "\">" + file + "</a>";

      mTo = "recipient.name@site.com";

      mSubject: "Notification: " + testResult;

      try

      {

        schema = "http://schemas.microsoft.com/cdo/configuration/";

        mConfig = Sys.OleObject("CDO.Configuration");

        mConfig.Fields.Item(schema + "sendusing") = 2; // send using SMTP

        mConfig.Fields.Item(schema + "smtpserver") = "123.456.789.001"; // IP address of Exchange server

        mConfig.Fields.Item(schema + "smtpserverport") = 25; // Port number

        mConfig.Fields.Item(schema + "MailboxURL")= "http://123.456.789.001/Exchange/user.name";

        //mConfig.Fields.Item(schema + "sendusername") = "user"; // User name (if needed)

        //mConfig.Fields.Item(schema + "sendpassword") = "pwd"; // User password (if needed)

        mConfig.Fields.Update();



        mMessage = Sys.OleObject("CDO.Message");

        mMessage.MimeFormatted = true;

        mMessage.Configuration = mConfig;

        mMessage.From = "Automated Test <noreply@site.com>";

        mMessage.To = mTo;

        mMessage.Subject = mSubject;

        mMessage.HTMLBody = mBody;

      

        mMessage.Send();

       

      }

      catch (exception)

      {

        Log.Error("E-mail cannot be sent", exception.description);

        return false;

      }

      Log.Message("Message to <" + mTo + "> was successfully sent");

      return true;

    }




    Thanks again,



    Marin