sending mail via CDO and office365.com
- 9 years ago
this script works pretty well (sent by a guy from SmartBear, thanks to him)
function Test()
{
SendEmail("FROM_EMAIL", "TO_EMAIL", "Test", "TestMessage", "");
}
function SendEmail(mFrom, mTo, mSubject, mBody, mAttachment)
{
var smtpServer = "smtp.office365.com";
var smtpPort = 25;
var userLogin = "user.name@domain.com";
var userPassword = "password";
var autentificationType = 1; // cdoBasic
var connectionTimeout = 15;
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") = smtpServer;
mConfig.Fields.Item(schema + "smtpserverport") = smtpPort;
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;
}