Using VBscript to send emails to Office 365 account

For some reason, we couldn't directly figure out how to use our normal VBscript that sends emails to send emails using an ExchangeOnline/Office 365 account. We tried all kinds of steps and it didn't work. So we eventually decided to just configure an SMTP service on our server using IIS 6 and then having our VBScript talk to the IIS SMTP service, which then sends the emails via Office 365.

Here are the steps:

1) Configure your IIS SMTP service using the steps in this Microsoft kbase article:

2) Configure VBScript code as follows:

Dim strBody

strBody = "Test email "

Dim ObjSendMail

Set ObjSendMail = CreateObject("CDO.Message")

'This section provides the configuration information for the remote SMTP server.

ObjSendMail.Configuration.Fields.Item ("") = 2

ObjSendMail.Configuration.Fields.Item ("") = ""

ObjSendMail.Configuration.Fields.Item ("") = 587

ObjSendMail.Configuration.Fields.Item ("") = 0

ObjSendMail.Configuration.Fields.Item ("") = 60

ObjSendMail.Configuration.Fields.Item ("") = 1

NOTE: these next two lines are the windows user id and password that has security permissions to connect to the

IIS server:

ObjSendMail.Configuration.Fields.Item ("") = "userid"

ObjSendMail.Configuration.Fields.Item ("") = "password"


ObjSendMail.To = ""

ObjSendMail.Subject = "test email "

ObjSendMail.From = ""

ObjSendMail.TextBody = strBody


Set ObjSendMail = Nothing

3) You have to go into the Office 365 admin portal and create a connector for the IP address of the IIS SMTP server.

Go to the Exchange Online admin center, then "mail flow" then "connectors". You have to add a rule that allows a connection from your IIS SMTP server.