Forum Discussion

sri99's avatar
sri99
Occasional Contributor
10 years ago

unable to send emails

I am unable to send emails in testcompelte, the test log shows emails cannot be sent, Please help me fix the below code

 

I am using the below code:

 

function Test()

{

SendEmail("test@gmail.com", "test@gmail.com", "Test", "TestMessage", "");

}

 

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

{

var smtpServer = "smtp.gmail.com";

var smtpPort = 587;

var userLogin = "testuser";

var userPassword = "testpassword";

var autentificationType = 1;

var connectionTimeout = 60;

var useSSL = true;

 

try {

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

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

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

   mConfig.Fields.Item(schema + "smtpserver") = smtp.googlemail.com;

   mConfig.Fields.Item(schema + "smtpserverport") = 465;

   mConfig.Fields.Item(schema + "sendusername") = userLogin;

   mConfig.Fields.Item(schema + "sendpassword") = userPassword;

   mConfig.Fields.Item(schema + "smtpauthenticate") = autentificationType;

   mConfig.Fields.Item(schema + "smtpusessl") = useSSL;

   mConfig.Fields.Item(schema + "smtpconnectiontimeout") =connectionTimeout;

   mConfig.Fields.Update();

  

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

   mMessage.Configuration = mConfig;

   mMessage.From = mFrom;

   mMessage.To = mTo;

   mMessage.Subject = mSubject;

   mMessage.HTMLBody = mBody;

  

   if(0 < mAttachment.length) {

     mMessage.AddAttachment(mAttachment);

   }

  

   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;

}