cancel
Showing results for 
Search instead for 
Did you mean: 

sending mail via CDO and office365.com

SOLVED
Highlighted
Valued Contributor

sending mail via CDO and office365.com

Hi,

 

we're migrating to Office365.com and I'm not longer able to use mails.

 

basicaly, my parameters are :

- sendusing 2

- smtpserver smtp.office365.com

- server port 25 or 587 (which are open both)

- smtpauthenticate 1

with or without sptmusessl

 

any help would be greatly appreciated

 

thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Valued Contributor

Re: sending mail via CDO and office365.com

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

View solution in original post

5 REPLIES 5
Highlighted
Community Hero

Re: sending mail via CDO and office365.com

Highlighted
Valued Contributor

Re: sending mail via CDO and office365.com

Hi Marsha,

 

We were already working with another provider without any problems.

The problem is with office365.com, don't seems to work with CDO.

I'm trying to figure it out with the support service,

Highlighted
Community Hero

Re: sending mail via CDO and office365.com

Hi,

 

Maybe the below will help...

https://clicdatacoder.wordpress.com/2012/07/13/sending-smtp-mail-via-office-365-exchange-using-cdo-m...

https://community.smartbear.com/t5/TestComplete-Functional-Web/How-to-send-an-email-using-office-365...

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Valued Contributor

Re: sending mail via CDO and office365.com

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

View solution in original post

Highlighted
Staff

Re: sending mail via CDO and office365.com

You're welcome!

 

 

Danny Nguyen
Associate Customer Support Engineer
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors