简体   繁体   English

如何使用IIS8和Classic ASP通过SMTP服务发送电子邮件?

[英]How to send email with SMTP service with IIS8 and Classic ASP?

I'm trying to send emails with classic ASP and IIS 8.5 for that I use SMTP Service (no SMTP Server) in IIS and a email account from Gmail. 我正在尝试使用经典ASP和IIS 8.5发送电子邮件,因为我在IIS中使用SMTP服务(无SMTP服务器),并使用来自Gmail的电子邮件帐户。

The error message when I'm testing the page is: 我在测试页面时的错误消息是:

CDO.Message.1 error '80040213'

Error de transporte en la conexión al servidor.

/anotala/prueba-Email.asp, línea 38

Mys ASP code is: Mys ASP代码是:

Set objConfig = Server.CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields

With Fields
 .Item(cdoSendUsingMethod)       = cdoSendUsingPort
 .Item(cdoSMTPServer)            = "smtp.gmail.com"

 .Item(cdoSMTPServerPort)        = 25
 '.Item(cdoSMTPConnectionTimeout) = 10
 .Item(cdoSMTPAuthenticate)      = cdoBasic
 .Item(cdoSendUserName)          = "emailaccount@gmail"
 .Item(cdoSendPassword)          = "pwd123"

 .Update
End With

Set objMessage = Server.CreateObject("CDO.Message")

Set objMessage.Configuration = objConfig

With objMessage
 .To       = "to@gmail.com"
 .From     = "from@gmail.com"                 
 .Subject  = "Prueba Nro. 1"
 .TextBody = "Este es el cuerpo de la prueba Nro. 1"
 .Send
End With

And this is the configuration of the IIS: 这是IIS的配置:

在此处输入图片说明

I would like to know where is the problem and How can I solve it? 我想知道问题出在哪里,如何解决?

http://www.w3schools.com/asp/asp_send_email.asp https://support.google.com/a/answer/176600?hl=es http://www.w3schools.com/asp/asp_send_email.asp https://support.google.com/a/answer/176600?hl=es

From your code it seems as if you are setting up your smtp connection in the code over using your IIS configuration. 从您的代码看来,好像您是通过使用IIS配置在代码中建立smtp连接的。 I do not believe you can use your IIS configuration with CDOSYS (see the answer here: https://stackoverflow.com/a/6489539/3915817 ). 我不相信您可以将IIS配置与CDOSYS一起使用(请参见此处的答案: https : //stackoverflow.com/a/6489539/3915817 )。 You alrerady have it properly set up in your code but this line 您已经在代码中正确设置了它,但是这一行

.Item(cdoSMTPServer)            = "smtp.gmail.com"

Indicates that you are using the SSL only version of google's smtp connection. 表示您使用的是Google的smtp连接的仅SSL版本。 This is actually good as you likely want to encrypt your username and password anyhow and not send them in plain text. 实际上,这很好,因为您可能希望以任何方式加密用户名和密码,而不是以纯文本形式发送它们。 You need to tell CDOSYS to use SSL though. 您需要告诉CDOSYS使用SSL。 you can do that by first using the correct port based on Google's API so I would change this your port line to: 您可以先使用基于Google API的正确端口来做到这一点,因此我将您的端口号更改为:

.Item(cdoSMTPServerPort)        = 465

and then you need to set up enabling SSL adding another constant 然后您需要设置启用SSL并添加另一个常量

Const cdoSendTLS = "http://schemas.microsoft.com/cdo/configuration/smtpusessl"

and add the item line to your fields block like so 并将项目行添加到您的字段块中,如下所示

.Item(cdoSendTLS) = 1

Sources: 资料来源:

http://www.saotn.org/authenticated-smtp-tlsscript-example-asp-php-aspnet-csharp-vbnet/#auth_smtp_tls_classic_asp http://www.saotn.org/authenticated-smtp-tlsscript-example-asp-php-aspnet-csharp-vbnet/#auth_smtp_tls_classic_asp

http://webcheatsheet.com/asp/sending_email_asp.php#remoteservergmail http://webcheatsheet.com/asp/sending_email_asp.php#remoteservergmail

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM