Link to home
Start Free TrialLog in
Avatar of tfinding
tfindingFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Use IIS to relay SMTP email within a VB Script

Hello

We currently have a VB Script (attached) that runs against certain clients & checks servers & services. It then sends an email via the client's Exchange server.

Recently one of our client's has started to use Office365, so they no longer need Exchange. Therefore, I need to amend the script to send the email via SMTP and IIS.

I have configured IIS & SMTP to send externally - this works with a backup application that sends Job alerts, so I just need to amend the script accordingly.

Thanking you in advance.
BCC.txt
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

I used to have a client that used office365. I seem to remember that you first have to log in and allow rely on whatever mail account you are using.

Make sure you are using the correct the correct smtp server. Instead of the ip, strSMTPServer should be set to smtp.office365.com port 587 and you will need authentication

https://support.office.com/en-au/article/Settings-for-POP-and-IMAP-access-for-Office-365-for-business-or-Microsoft-Exchange-accounts-7fc677eb-2491-4cbc-8153-8e7113525f6c

https://social.msdn.microsoft.com/Forums/en-US/71d50521-3e19-4ae3-a455-ebbf5375be35/sending-mails-thru-microsoft-office-365?forum=visualfoxprogeneral
SOLUTION
Avatar of tfinding
tfinding
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tfinding

ASKER

Hi Scott - sorry for the delay

I changed it thus;

strSMTPServer       = "smtp.office365.com"
strFrom             = "Client Name <administrator@client-name.onmicrosoft.com>"

With objMsg.Configuration.Fields
        sch = "http://schemas.microsoft.com/cdo/configuration/"
        .Item (sch & "sendusing") = 2
        .Item (sch & "smtpserver") = strSMTPServer
        .Item (sch & "smtpserverport") = 587
      .Item (sch & "sendusername") = "administrator@client-name.onmicrosoft.com"
      .Item (sch & "sendpassword") = "password"
      .Item (sch & "sendusessl") = 1
      .Item (sch & "sendauthenticate") = 1
        .Update
    End With

It ends with a Windows Script Host error on the line which states : objMsg.Send;

Error : The transport failed to connect to the server
Code : 80040213
Source : CDO.Message.1

Many thanks again
Are you sure you have authorized remote for this account?
Hi Scott

Yes, because I am sending the backup job alerts through smtp.office365.com.
I had a client that  used to use office365 and I  had this working with cdo.  I will hunt around to see if I can find the code I used.
Many thanks.

As an aside, if I create a .txt file with a recipient/sender address into the Inetpub\mailroot\pickup folder, this is delivered to the recipient without issue.

Therefore, the SMTP virtual server within IIS 6.0 is ok. Again, it's using smtp.office365.com as the smart host for the routed domain.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Had to play around with the script & the SMTP Virtual server to get this working - all contributions allowed me to pursue & check all settings.