email - 使用带有 CDOSYS 的 gmail smtp 服务器发送电子邮件时出错

标签 email asp-classic gmail windows-server-2008-r2 cdo.message

我的 asp 页面出现错误

错误“80040211” /contact_us1.asp,第 106 行

第106行是ObjSendMail.Send方法调用。以下代码是通过 CDOSYS 发送电子邮件的完整过程,并且没有安装 smtp 服务器。

操作系统 - Windows Server2008R2, IIS - 7.5

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%
'Declaring Variables
Dim smtpserver,youremail,yourpassword,ContactUs_Name,ContactUs_Tel,ContactUs_Email
Dim ContactUs_Subject,ContactUs_Body,Action,IsError


' Edit these 3 values accordingly.. leave the smtp server alone as it is set for Gmail
smtpserver = "smtp.gmail.com"
youremail = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="afdcc0c2cac0c1caefc8c2cec6c381ccc0c2" rel="noreferrer noopener nofollow">[email protected]</a>"
yourpassword = "--------"



' Grabbing variables from the form post
ContactUs_Name = Request("ContactUs_Name")
ContactUs_Tel = Request("ContactUs_Tel")
ContactUs_Email = Request("ContactUs_Email")
ContactUs_Subject = Request("ContactUs_Subject")
ContactUs_Body = Request("ContactUs_Body")
Action = Request("Action")

' Used to check that the email entered is in a valid format
Function IsValidEmail(Email)
    Dim ValidFlag,BadFlag,atCount,atLoop,SpecialFlag,UserName,DomainName,atChr,tAry1
    ValidFlag = False
        If (Email <> "") And (InStr(1, Email, "@") > 0) And (InStr(1, Email, ".") > 0) Then
            atCount = 0
            SpecialFlag = False
            For atLoop = 1 To Len(Email)
            atChr = Mid(Email, atLoop, 1)
                If atChr = "@" Then atCount = atCount + 1
                If (atChr >= Chr(32)) And (atChr <= Chr(44)) Then SpecialFlag = True
                If (atChr = Chr(47)) Or (atChr = Chr(96)) Or (atChr >= Chr(123)) Then SpecialFlag = True
                If (atChr >= Chr(58)) And (atChr <= Chr(63)) Then SpecialFlag = True
                If (atChr >= Chr(91)) And (atChr <= Chr(94)) Then SpecialFlag = True
            Next
            If (atCount = 1) And (SpecialFlag = False) Then
                BadFlag = False
                tAry1 = Split(Email, "@")
                UserName = tAry1(0)
                DomainName = tAry1(1)
            If (UserName = "") Or (DomainName = "") Then BadFlag = True
            If Mid(DomainName, 1, 1) = "." then BadFlag = True
            If Mid(DomainName, Len(DomainName), 1) = "." then BadFlag = True
                ValidFlag = True
            End If
        End If
        If BadFlag = True Then ValidFlag = False
        IsValidEmail = ValidFlag
End Function
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>

<body class="oneColFixCtrHdr" onload="P7_initPM(0,0,1,-20,10)">

<%
' If there were no input errors and the action of the form is "SendEMail" we send the email off
If Action = "SendEmail" Then

    Dim strBody

    ' Here we create a nice looking html body for the email
    strBody = strBody & "<font face=""Arial"">Contact Us Form submitted at " & Now() &  vbCrLf & "<br><br>"
'   strBody = strBody & "From http://" & Request.ServerVariables("HTTP_HOST") &  vbCrLf & "<br>"
'   strBody = strBody & "IP " & Request.ServerVariables("REMOTE_ADDR") & vbCrLf & "<br>"
    strBody = strBody & "Name" & " : " & " " & Replace(ContactUs_Name,vbCr,"<br>") & "<br>"
    strBody = strBody & "Tel." & " : " & " " & Replace(ContactUs_Tel,vbCr,"<br>") & "<br>"
    strBody = strBody & "Email" & " : " & " " & Replace(ContactUs_Email,vbCr,"<br>") & "<br>"
    strBody = strBody & "Subject" & " : " & " " & Replace(ContactUs_Subject,vbCr,"<br>") & "<br>"
    strBody = strBody & "<br>" & Replace(ContactUs_Body,vbCr,"<br>") & "<br>"
    strBody = strBody & "</font>"

    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") = "smtp.gmail.com"
    ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 
    ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1 'Use SSL for the connection
    ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

    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") = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c5b6aaa8a0aaaba085a2a8a4aca9eba6aaa8" rel="noreferrer noopener nofollow">[email protected]</a>"
    ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "----------"

    ObjSendMail.Configuration.Fields.Update

    'End remote SMTP server configuration section==

    ObjSendMail.To = youremail
    ObjSendMail.CC = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="93f8f2e1f2e3f6e7eaf2fdbdfef2fde6f8d3f4fef2faffbdf0fcfe" rel="noreferrer noopener nofollow">[email protected]</a>;<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fd96909c938896bd909c9491d38f88" rel="noreferrer noopener nofollow">[email protected]</a>"
    ObjSendMail.Subject = ContactUs_Subject
    ObjSendMail.From = ContactUs_Email

    ' we are sending a html email.. simply switch the comments around to send a text email instead
    ObjSendMail.HTMLBody = strBody
    'ObjSendMail.TextBody = strBody

    ObjSendMail.Send

    Set ObjSendMail = Nothing 

' change the success messages below to say or do whatever you like
' you could do a response.redirect or offer a hyperlink somewhere.. etc etc
%>
<font size="12">Message uxarkvec barehajox</font>
<% 
Else 
%>
            <form action="contact_us1.asp" method="POST">
                <input type="hidden" name="Action" value="SendEmail">
                    <table border="0" cellspacing="1" style="font-size:14px; font-family:Verdana, Geneva, sans-serif;">
                        <tr>
                            <td valign="top">
                                Full Name:
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <input type="text" name="ContactUs_Name" size="35" value="<% =ContactUs_Name %>" required>
                            </td>
                        </tr>
                        <tr>
                            <td valign="top">
                                Tel.:
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <input type="text" name="ContactUs_Tel" size="35" value="<% =ContactUs_Tel %>">
                            </td>
                        </tr>
                        <tr>
                            <td valign="top">
                                Email:
                            </td>
                        </tr>
                        <tr>    
                            <td colspan="2">
                                <input type="text" name="ContactUs_Email" size="35" value="<% =ContactUs_Email %>" required>
                            </td>
                        </tr>
                        <tr>
                            <td valign="top">
                                Subject:
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <input type="text" name="ContactUs_Subject" value="<% =ContactUs_Subject %>" size="35">
                            </td>
                        </tr>
                        <tr>
                            <td valign="top">
                                Message:
                            </td>
                        </tr>
                        <tr>
                            <td valign="top">
                                <textarea  cols="60" name="ContactUs_Body" wrap="soft" style="resize:none; height: 150px" required><% =ContactUs_Body %></textarea>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <input type="submit" value="Send Message" style="font-size:16px">
                            </td>
                        </tr>
                    </table>
                </form>

<% 
End If 
%>

</body>
</html>

请帮我解决这个问题。

最佳答案

我的 Gmail 也遇到同样的问题。只需两步即可解决问题:

  1. 将密码更改为强密码! 弱密码不起作用!
  2. myaccount.google.com > 安全 > 安全性较低的应用访问 > 开启

关于email - 使用带有 CDOSYS 的 gmail smtp 服务器发送电子邮件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19223811/

相关文章:

forms - 如果在 IE 9 上访问 Gmail 上的表单链接,文件上传不起作用

html - gmail 如何保留复制和粘贴的网页内容,维护附加的 CSS?

html - 使用 AlternateView 生成 HTML 电子邮件的正确语法

VBA Excel Outlook 电子邮件正文格式

PHP 使用 mail() 发送 html - 某些服务器以文本形式接收

asp-classic - 经典 ASP 中的简单加密/解密函数

asp-classic - 类型不匹配: 'Server.HTMLEncode' ASP

Javascript 正则表达式 - 限制有效字符数

javascript - 读取文本文件上下文而不将其保存在服务器上 - Asp classic

gmail - Google 多重登录 - 有没有办法在 URL 中指定帐户?