使用经典asp发送电子邮件

时间:2013-01-03 09:49:26

标签: html email asp-classic smtp sendmessage

我很有兴趣通过asp页面发送电子邮件。 我在互联网上照顾它,我找到了一些东西。

<%
    sch = "http://schemas.microsoft.com/cdo/configuration/" 

    Set cdoConfig = CreateObject("CDO.Configuration") 

    With cdoConfig.Fields 
        .Item(sch & "sendusing") = 2 ' cdoSendUsingPort 
        .Item(sch & "smtpserver") = "smtp.gmail.com" 
        .update 
    End With 

    Set cdoMessage = CreateObject("CDO.Message") 

    With cdoMessage 
        Set .Configuration = cdoConfig 
        .From = Request.Form("From")
        .To = Request.Form("To") 
        .Subject = Request.Form("Subject")
        .TextBody = Request.Form("Body") 
        .Send 
    End With 

       Set cdoMessage = Nothing 
       Set cdoConfig = Nothing 
   %>

但它没有向我发送电子邮件,其中说“流量无法连接到服务器”,我应该在代码中更改什么?

非常感谢。

1 个答案:

答案 0 :(得分:0)

我认为您必须为smtp服务器设置用户名和密码,并将“smtpauthenticate”属性设置为true:

.item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.item("http://schemas.microsoft.com/cdo/configuration/sendusername") = usrName
.item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = pwd
相关问题