无法向SMTP服务器发送消息。传输错误0x80040217

时间:2015-02-06 11:06:26

标签: email vbscript asp-classic cdo.message

使用gmail通过asp发送邮件时出现此错误,我已经使用了端口465,587和25,结果相同

昏暗的邮件 将email2变暗为字符串 dim urlms as string

Dim mail 
dim email2 as string
dim urlms as string
				

mail = CreateObject("CDO.Message") 			
urlms = "http://schemas.microsoft.com/cdo/configuration/"	
mail.Configuration.Fields.Item(urlms  & "sendusing") = 2 'enviar usando port
mail.Configuration.Fields.Item(urlms  & "smtpserver") = "smtp.gmail.com"
mail.Configuration.Fields.Item(urlms  & "smtpserverport") = 465
mail.Configuration.Fields.Item(urlms  & "smtpusessl") = True
mail.Configuration.Fields.Item(urlms  & "smtpconnectiontimeout") = 60
mail.Configuration.Fields.Item(urlms + "smtpauthenticate") = 1
mail.Configuration.Fields.Item(urlms + "sendusername") = "" 'login
mail.Configuration.Fields.Item(urlms + "sendpassword") = "" 'password

mail.Configuration.Fields.Update

mail.Send

4 个答案:

答案 0 :(得分:1)

如果您在Google帐户中使用两步验证,则需要更改设置,选择"启用较少的安全应用"或者生成16个字符的应用程序密码,您需要在代码中使用它而不是实际的Gmail密码。 https://www.google.com/settings/security/lesssecureapps

答案 1 :(得分:0)

//
// MessageId: CDO_E_LOGON_FAILURE
//
// MessageText:
//
// The transport was unable to log on to the server.
//
#define CDO_E_LOGON_FAILURE              0x80040217L

另外,为什么你使用plus来连接三个配置项。

您的代码将所有内容变暗两次。它将事物视为字符串。

您正在创建对象而不使用Set。

我怀疑你的代码会运行以产生错误。

答案 2 :(得分:0)

它对我自己的邮件服务器来说就像一个魅力,但它失败了Gmail我不知道为什么......

无论如何,我也尝试过没有加分并且也没有工作,最后我用了这个:



Dim ObjSendMail
Set ObjSendMail = CreateObject("CDO.Message") 
     
'This section provides the configuration information for the remote SMTP server.
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="mail.yoursite.com"
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 ' or 587
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
     
' Google apps mail servers require outgoing authentication. Use a valid email address and password registered with Google Apps.
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="somemail@yourserver.com" 'your Google apps mailbox address
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="yourpassword" 'Google apps password for that mailbox
     
ObjSendMail.Configuration.Fields.Update
     
ObjSendMail.To = "someone@someone.net"
ObjSendMail.Subject = "this is the subject"
ObjSendMail.From = "someone@someone.net"
     
' we are sending a text email.. simply switch the comments around to send an html email instead
'ObjSendMail.HTMLBody = "this is the body"
ObjSendMail.TextBody = "this is the body"
     
ObjSendMail.Send
     
Set ObjSendMail = Nothing 




http://somee.com/DOKA/DoHelpTopics.aspx?docode=false&thnid=102

对我的服务器起了很大的作用,但它对gmail没有用。

答案 3 :(得分:0)

注意:消息显示LOGON ERROR。确保名称和密码正确无误。

Set emailObj      = CreateObject("CDO.Message")
emailObj.From     = "dc@gail.com"

emailObj.To       = "dc@gail.com"

emailObj.Subject  = "Test CDO"
emailObj.TextBody = "Test CDO"

Set emailConfig = emailObj.Configuration
msgbox emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") 
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing")    = 2  
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1  
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl")      = true 
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername")    = "YourUserName"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword")    = "Password1"
emailConfig.Fields.Update

emailObj.Send

If err.number = 0 then Msgbox "Done"