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 work at first, but after some more tries, i cant get any emails.

  • 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;


    }

5 Replies

  • jose_pita's avatar
    jose_pita
    Super Contributor

    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;


    }

  • sarlcool's avatar
    sarlcool
    Occasional Contributor
    the trace code said that the message is sent. but there is no trace of the mail.

    it doesnt show up on Spam.



    will this work with Microsoft Exchange server?

    if so, what would i need to change?

    can you add comments to the code as to what is that for?

    it would help a lot.



    thanks.
  • sarlcool's avatar
    sarlcool
    Occasional Contributor
    Hi Jose Pita,

    Your code worked. Just needed to set some correct values for the port number.



    by the way, what needs to be added if i want to add some attachments?
  • jose_pita's avatar
    jose_pita
    Super Contributor
    http://support.smartbear.com/viewarticle/26637/



    SendMail("ClareJ@clarejeffersoncorp.com", "mail.johnsmithcorp.com", "John Smith", "JohnS@johnsmithcorp.com", "Notification", "Hello Clare, Your application is nice.", "C:/File1.txt", "C:/File2.txt")



    w
    hen you call the function you just need to add the path to the files you want to send.



    Beware of the size of the files, if they are too big you may encounter problems, I use an intranet shared folder or dropbox.
  • sarlcool's avatar
    sarlcool
    Occasional Contributor
    i already tried the built-in before. it wont work.