user999684
user999684

Reputation: 761

CDO VBS Script for office 365 not working

I modified a VBS script to send authenticated email through my office 365 account, but cannot get it to work. I get the error: sendemail365.vbs(17, 2) (null): The server rejected the sender address.

The server response was:

530 5.7.57 SMTP; Client was not aut
henticated to send anonymous mail during MAIL FROM [DM5PR06CA0041.namprd06.prod.
outlook.com].  

I can connect using the email address in thunderbird and send emails authenticated. Any suggestions what I need to tweak? Everything I research seems to be very old and does not work.

   Set objEmail      = CreateObject("CDO.Message")
 objEmail.From     = "[email protected]"
 objEmail.To = "[email protected]"
 objEmail.Subject  = "Testing office 365 Subject"
 objEmail.Textbody = "Testing office 365 body"
 with objEmail.Configuration.Fields
  .Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")        = 2
  .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver")       = "smtp-mail.outlook.com"
  .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")   = 587
  .Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
  .Item ("http://schemas.microsoft.com/cdo/configuration/sendusername")     = "dummy@dummycom"
  .Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword")     = "password(actualpassword)"
  .Item ("http://schemas.microsoft.com/cdo/configuration/sendtls")          = True
  .Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
  .Update
 end with
 objEmail.Send

Upvotes: 0

Views: 3682

Answers (1)

lloydpick
lloydpick

Reputation: 1649

The issue here stems from your e-mail provider rather than anything to do with your code. See this post from Microsoft about direct sends...

This indicates that you are connecting to the SMTP client submission endpoint (smtp.office365.com), which can't be used for direct send. For direct send, use the MX endpoint for your Office 365 tenant, which ends with "mail.protection.outlook.com." So, please let your admin check the MX record. Moreover, please check if the SMTP port is 25/TLS.

Upvotes: 1

Related Questions