Forum Discussion

marin's avatar
marin
Frequent Contributor
14 years ago

Questions on eMail sending

Hello all,



I have two questions on eMail send functions:



1. Where to supply credentials for outgoing SMTP server in BuiltIn.SendMail() method?

2. When using Collaboration Data Objects (CDO) for sending eMail (as described in help document in TC in "Sending E-Mail From Scripts"), Outlook seems to declare incoming attachment as .eml (=attached Outlook item), even though it was attached as .mht file (TC log). Received attachment would appear in Outlook (v.2010)  as e.g. MyResults.mht.eml - screenshot attached.

Is there a way to prevent automatic adding of that suffix when received in Outlook?



Many thanks for any hints,



Marin

4 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    BuiltIn.SendMail uses the MAPI mail credentials in the OS environment so you don't need to supply the credentials in the method.



    As for your problem with attachments, could you post the code that you're using?  It would be interesting to see how you're doing the attachment.
  • marin's avatar
    marin
    Frequent Contributor
    Hello Robert,



    many thanks for your reply, much appreciated...



    1. I wonder if you could explain what are "MAPI mail credentials in OS environment"? I'm afraid I do not know what these are and where exactly they need to be set.



    2. This is the code I am using:





    function SendEmail(mFrom, mTo, mSubject, mBody, mAttach)

    {

      var i, schema, mConfig, mMessage;



      try

      {

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

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

        mConfig.Fields.Item(schema + "sendusing") = 2; // cdoSendUsingPort

        mConfig.Fields.Item(schema + "smtpserver") = "xxx.mail.xxx"; // SMTP server

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

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

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

        mConfig.Fields.Update();



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

        mMessage.MimeFormatted = true;

        mMessage.Configuration = mConfig;

        mMessage.From = mFrom;

        mMessage.To = mTo;

        mMessage.Subject = mSubject;

        mMessage.HTMLBody = mBody;

     

        mMessage.AddAttachment(mAttach);  //mAttach is a string with full path to .mht file e.g. "C:\temp\MyResults.mht"

        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
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Using JScript, you need to make sure that your string for your path is more like



    "C:\\temp\\MyResults.mht"




    As the backslash character is a special character.



    As for MAPI... this is essentially, if you go to Windows Control Panel and select the Mail icon, the protocols (SMTP, MS Exchange, etc) configured there is what TC uses for sending mail.  In other words, you need to have an e-mail client of some sort set up on your workstation to use BuiltIn.SendMail and the credentials of that email client are what are used to actually send the mail.