Link to home
Start Free TrialLog in
Avatar of brownmetals
brownmetals

asked on

SMTP Relay with Office 365 using Classic ASP

I am trying to send a CDO email message using Classic ASP (VBScript) and Office 365. I have tried everything I can think of in the documentation (http://community.office365.com/en-us/wikis/exchange/how-to-setup-an-smtp-relay-in-office-365.aspx), but I can't get this to work. Has anyone else had success with their SMTP relay setup using ASP/CDO?


      Set objMail=CreateObject("CDO.Message")
      Set iConf = CreateObject("CDO.Configuration")
      Set Flds = iConf.Fields
      With Flds
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.office365.com"  'also tried mydomain-com.mail.protection.outlook.com
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587  'tried 25 and 587
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "MyOffice365Email@myDomain.com"      
    .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "myPassword"
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1      'cdoBasic
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl ") = true            
            .Update
      End With      
With objMail
   Set .Configuration = iConf
   .From = empEmail
   .To = EmailAddress
   .BCC = empEmail
   .Subject = "My Subject Line Here"
   .HTMLBody = msgBody
   .Send
End With
SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America 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 brownmetals
brownmetals

ASKER

Thanks for the feedback. I've tried all of the solutions here and continue to receive this error message related to the CDO Send() command.

error '8004020e'

My research tells me that this is most likely an authentication issue with Office 365 where the Office 365 servers are rejecting the attempt because I do not have permission to send through their servers. I'll continue to work on it, but let me know if you have any other suggestions.

Thanks!
J
Your solution sounds valid.  But without knowing the line number it's hard to tell.  

There are a lot of variables with email.
Read through their info http://support.microsoft.com/kb/2600912

You may have to authorize on the ms site.
try change the auth to NTLM:

  .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 2

Open in new window


also try using SMTP server IP address instead of name
The error sites the line that has the "SEND" command on it so it's happening at the point the email is trying to be sent using the Office 365 servers.

I've been using this info as well to try and get this to work:
http://community.office365.com/en-us/wikis/exchange/how-to-setup-an-smtp-relay-in-office-365.aspx

The middle column uses "mydomain-com.mail.protection.outlook.com" to send via SMTP relay. I have not been able to get that to work. My cloud migration vendor has suggested that the best option is to use the 1st column using "smtp.office365.com" and Port 587 with TLS encryption. The only setting I can find that remotely resembles TLS encryption is the smtpUsesSSL attribute and set it to true. However, I'm not sure that the Classic ASP smtpUsesSSL setting is compatible with Microsoft's SSL/TLS to establish a connection.

For my copier to send scanned images via email, I was able to get it to work using the settings from the 1st column, but I haven't had such luck with Classic ASP applications. Any other suggestions?
I've tried changing smtpauthenticate to a value of 2 and it produced the same error.

Microsoft changes the IP addresses of their email servers regularly, so using an IP address as opposed to the FQDN would not produce a reliable solution.

Thanks for the continued support. Further suggestions are certainly appreciated.
I was able to eliminate the error message by using this configuration shown here:

http://www.saotn.org/the-sendusing-configuration-value-is-invalid/#smtp_auth_tls_asp

However, the email is still not coming through which makes me think that Office 365 servers are still blocking it for some reason. I am using a valid Office 365 user's email account as the FROM address, but for some reason, it still does not go through. Any other suggestions?

Thanks,
J
Is it in your spam folder?
I wish it were that easy. :-) No, not in the spam folder.
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
That is probably wise!  What did you end up with?
McAfee Saas Email Protection - easy to incorporate into Classic ASP code and all other devices like printers, servers, and copiers and all messages (inbound and outbound) are scanned for malware. It's a slam dunk! Thanks again for your suggestions.
I found a better alternative than Office 365. Please see my comment above.