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

狂风中的少年 提交于 2019-12-24 04:09:05

问题


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@domain.com"
ObjSendMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
ObjSendMail.Configuration.Fields.Update

ObjSendMail.To = "to_email@anotherdomain.com"
ObjSendMail.Subject = mailSubject
ObjSendMail.From = """From Name"" <email@domain.com>"
'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@domain.com", "password")
    mailClient.Credentials = cred
    Dim message As New MailMessage()
    message.From = New MailAddress("email@domain.com", "From Name")
    message.[To].Add("to_email@anotherdomain.com")
    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.


回答1:


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.



来源:https://stackoverflow.com/questions/32787184/office-365-and-classic-asp-vs-vb-net-smtp-settings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!