Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Office 365 and Classic ASP vs. VB.net SMTP Settings

There are several questions about classic ASP and Office 365, but none that seem to answer my particular scenario, so here goes.

I set up an email account on Office 365 and am trying to do an SMTP test with the following code:

Dim ObjSendMail, mailSubject, mailBody
Set ObjSendMail = CreateObject("CDO.Message")
mailSubject = "Test"
mailBody = "Test"
ObjSendMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
ObjSendMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.office365.com"
ObjSendMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
ObjSendMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
ObjSendMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 240
ObjSendMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
ObjSendMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "[email protected]"
ObjSendMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
ObjSendMail.Configuration.Fields.Update

ObjSendMail.To = "[email protected]"
ObjSendMail.Subject = mailSubject
ObjSendMail.From = """From Name"" <[email protected]>"
'ObjSendMail.HTMLBody = "this is the body"
ObjSendMail.TextBody = mailBody
ObjSendMail.Send

This generates the following error:

CDO.Message.1 error '80040213'

The transport failed to connect to the server.

I've figured out that it's due to the smtpusessl setting, but I need that, and if I turn it off I get error '8004020e'.

Now, here's the weird thing...I can do the SMTP test successfully using VB.net and the code below:

    Dim mailClient As New SmtpClient("smtp.office365.com")
    mailClient.Port = 587
    mailClient.EnableSsl = True
    'Your network credentials are going to be the Office 365 email address and the password
    Dim cred As New System.Net.NetworkCredential("[email protected]", "password")
    mailClient.Credentials = cred
    Dim message As New MailMessage()
    message.From = New MailAddress("[email protected]", "From Name")
    message.[To].Add("[email protected]")
    message.Subject = "Test Office 365 SMTP"
    message.Body = "Test Body"
    mailClient.Send(message)

This tells me that I shouldn't need to configure anything on my server to get the classic ASP version to work...which is what the site I'm working on is built in. The question I have is...what stupid setting am I missing that will get rid of the transport error?

Thanks.

like image 205
SEFL Avatar asked Oct 19 '25 06:10

SEFL


1 Answers

Try port 25 instead of 587. All of your other settings, including smtpusessl, can remain the same.

I suspect the problem with port 587 is that CDO.Message doesn't support the protocol required (TLS? MSA?). I found a few other internet posts stating the same problem with ASP/VBScript and port 587 but that .NET applications did not have this problem.

like image 128
Keith Avatar answered Oct 21 '25 20:10

Keith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!