繁体   English   中英

使用带有CDOSYS的gmail smtp服务器发送错误电子邮件

[英]Error email send using gmail smtp server with CDOSYS

我在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 = "someone@gmail.com"
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") = "someone@gmail.com"
    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 = "karapetyan.manuk@gmail.com;kmanuk@mail.ru"
    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>

请帮助我解决此问题。

<html>
<head>
</head>
<body>

<br> start


<%
dim smtpserver, youremail, yourpassword
smtpserver = "smtp.gmail.com"
youremail = "yyyy@gmail.com"
yourpassword = "xxxxx" 

Dim ObjSendMail
Set ObjSendMail = CreateObject("CDO.Configuration")
Set objSendmsg =  CreateObject ("CDO.Message") 
ObjSendMail.Fields ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
ObjSendMail.Fields ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpserver
ObjSendMail.Fields ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
ObjSendMail.Fields ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true 'Use SSL for the connection
ObjSendMail.Fields ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") =60
ObjSendMail.Fields ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
ObjSendMail.Fields ("http://schemas.microsoft.com/cdo/configuration/sendusername") = youremail
ObjSendMail.Fields ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = yourpassword
ObjSendMail.Fields.Update
set objSendmsg.Configuration = ObjSendMail



objSendmsg.To = youremail
'ObjSendMail.CC = "cccccc.dddddd@sunarctechnologies.com"
objSendmsg.Subject = "Auto mail from ASPSubject"
objSendmsg.From = youremail
objSendmsg.HTMLBody = "<p>hello</p>"
objSendmsg.Send
response.Write "Mail Sent Successfully!<br />Check your Inbox for: "
Set ObjSendMail = Nothing 
set objSendmsg = nothing 
%>



</body>

</html>
my above programme is also giving same error please help

我在使用gmail时遇到了同样的问题。 仅需两个步骤即可解决问题:

  1. 将密码更改为强密码! 弱密码无法正常工作
  2. myaccount.google.com>登录和安全>已连接的应用和网站>允许安全程度较低的应用:开启

暂无
暂无

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

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