Forum Discussion

sarlcool's avatar
sarlcool
Occasional Contributor
11 years ago
Solved

Sending Emails using two methods doesnt seem to work.

First method: Using Outlook: It seems that the sample mailing script cannot initialize Outlook 2013. Please help on how to do this. Second method: Using SendMail() function: This seemed to...
  • jose_pita's avatar
    11 years ago

    When you use the sendMail() function it sends the mail with sucess? Have you checked your spam inbox?


     


    I used the sendMail() function like this:(emails go to spam, can't get it to work with gmail though...)


     


    if( SendEmail("FROMEMAIL", "TOEMAIL", "SUBJECT", "MESSAGE") )


        Log.Message("Message was sent");


      else


        Log.Warning("Message was not sent");  


     


     


    function SendEmail(mFrom, mTo, mSubject, mBody)


    {


      var i, schema, mConfig, mMessage;


     


      try


      {



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


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


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


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


        mConfig.Fields.Item(schema + "smtpauthenticate") = 1; // Authentication mechanism


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


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


        mConfig.Fields.Update();


     


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


        mMessage.Configuration = mConfig;


        mMessage.From = mFrom;


        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;


    }