asp 发送邮件

<h1 style="text-align:center!important;color:red!important; ">ASP CDO.Message 发送邮件完整实例 By shawl.qiu</h1>
<h2 style="float:right!important;margin:0px;padding:0px; "><a href=" http://blog.csdn.net/btbtd">shawl.qiu</a> code</h2>
<%    
    dim mAction, mFrom, mTo, mCC, mBcc, mSubject, mBody
    dim mSmtp, mPort, mTimeout, mSsl, mUser, mPwd
        mAction="?id=cdo"
        mFrom="shawlqiu@21cn.com"
        mTo="shawl.qiu@gmail.com,btbtd@msn.com"
        mCc="btbtd@yahoo.com.cn"
        mBcc="shawl.qiu+2@gmail.com"
        mSubject="mail subject"
        mBody="test mail body"&chr(13)&"中文"&chr(13)&"<h2>html format</h2>"
        mSmtp="smtp.21cn.com"
        mPort=25
        mTimeout=60
        mUser="shawlqiu"
        mPwd="不告诉你"
        
    dim qId:qId=request.queryString("id")
    
    call fCdoSendMail(qId,request.form)
    
    if qId<>"cdo" then _
    call fCdoForm(mAction,mFrom, mTo, mCc, mBcc, mSubject, mBody, mSmtp, mPort, mTimeout, mUser, mPwd)
    
    function fCdoSendMail(rQs, rForm)
    '''''''''''''''''''''''''''''''''''''''''''''''''''
    ' ASP CDO.Message 发送邮件完整实例 By shawl.qiu
    ' CDO 发送邮件操作函数 fCdoSendMail
    '''''''''''''''''''''''
    ' 参数说明:
    ''''''''''''''
    ' rQs = request.queryString(id)
    ' rForm = request.Form 集合
    '''''''''''''''''''''''
    ' sample call: 
    ''''''''''''''
    ' call fCdoSendMail(qId,request.form)
    '''''''''''''''''''''''''''''''''''''''''''''''''''
        if rQs="" or rQs<>"cdo" then exit function
        if isObject(rForm)=false then exit function
        dim temp
        for each temp in rForm
            select case temp
                case "mTextBody"
                case "mHtmlBody"
                case "mFile"
                case "mSsl"
                case else
                    execute "dim "&temp&":"&temp&"=request.form(temp)"
            end select
        next
        dim mSsl, mTextBody, mHtmlBody
            mSsl=request.form("mSsl")
            mTextBody=request.form("mTextBody")
            mHtmlBody=request.form("mHtmlBody")
            mBody="<meta http-equiv=""Content-Type"" content=""text/html; charset=gb2312"" />"&chr(13)&mBody
            
            if mSsl="" then mSsl=false else mSsl=true
        dim cdo 
            set cdo=createObject("cdo.message")
                'configuration information for the remote SMTP Server
                with cdo.configuration.fields
                    .Item(" http://schemas.microsoft.com/cdo/configuration/sendusing") = mSend
                    .item(" http://schemas.microsoft.com/cdo/configuration/smtpserver")= mSmtp 'SMTP 服务器地址
                    .item(" http://schemas.microsoft.com/cdo/configuration/smtpserverport")= mPort '端口 25
                    .item(" http://schemas.microsoft.com/cdo/configuration/sendusername")= mUser '用户名
                    .item(" http://schemas.microsoft.com/cdo/configuration/sendpassword")= mPwd '用户密码
                    .item(" http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")= mAuth 'NONE, Basic (Base64 encoded), NTLM
                    .item(" http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout")= mTimeout '超时设置, 以秒为单位
                    .Item(" http://schemas.microsoft.com/cdo/configuration/smtpusessl") = mSsl '是否使用套接字 true/false 
                    .Update
                end with
                with cdo
                    .from=mFrom
                    .to=mTo
                    if mCc<>"" then .cc=mCc
                    if mBcc<>"" then .bcc=mBcc
                    .subject=mSubject
                    if mTextBody<>"" then .textbody=mBody
                    if mHtmlBody<>"" then .htmlbody=mBody
                    
                    'if len(mFile)>0 then .Addattachment mFile
                    '// CDO 发附件规则: 当前目录的文件可用变量, 不是当前的目录不能用变量
                    On Error Resume Next
                    .send
                    if err.number<>0 then response.write "邮件发送失败, 错误编号: "&_
                    err.number&"<br/>错误描述: "&err.description else response.write "邮件已发送"
                end with 'shawl.qiu code'
            set cdo=nothing
        end function
    function fCdoForm(mAction,mFrom, mTo, mCc, mBcc, mSubject, mBody, mSmtp, mPort, mTimeout, mUser, mPwd)
    if mAction="" then exit function
    '''''''''''''''''''''''''''''''''''''''''''''''''''
    ' ASP CDO.Message 发送邮件完整实例 By shawl.qiu
    ' CDO 发送邮件表单函数 fCdoForm
    '''''''''''''''''''''''
    ' 参数说明: (除 mAction 外, 其余参数值不是必须)
    ''''''''''''''
    ' mAction= 表单提交 URL, 如: ?id=cdo
    ' mFrom= 发件人 Email
    ' mTo= 收件人 Email
    ' mCc= 收件人 Email
    ' mBcc= 收件人 Email
    ' mSubject= 邮件标题
    ' mBody= 邮件内容
    ' mSmtp= SMTP 服务器地址, 如: smtp.21cn.com
    ' mPort= SMTP 端口, 如: 25
    ' mTimeout= 超时限制, 如: 60(单位为秒)
    ' mUser= 用户名
    ' mPwd= 密码
    '''''''''''''''''''''''
    ' sample call: 
    ''''''''''''''
    ' dim mAction, mFrom, mTo, mCC, mBcc, mSubject, mBody
    ' dim mSmtp, mPort, mTimeout, mSsl, mUser, mPwd
    '     mAction="?id=cdo"
    '     mFrom="shawlqiu@21cn.com"
    '     mTo="shawl.qiu@gmail.com,btbtd@msn.com"
    '     mCc="btbtd@yahoo.com.cn"
    '     mBcc="shawl.qiu+2@gmail.com"
    '     mSubject="mail subject"
    '     mBody="test mail body"&chr(13)&"中文"&chr(13)&"<h2>html format</h2>"
    '     mSmtp="smtp.21cn.com"
    '     mPort=25
    '     mTimeout=60
    '     mUser="shawlqiu"
    '     mPwd="yourPassword"
    ' call fCdoForm(mAction,mFrom, mTo, mCc, mBcc, mSubject, mBody, mSmtp, mPort, mTimeout, mUser, mPwd)
    '''''''''''''''''''''''''''''''''''''''''''''''''''    
%>
        <form action="<% response.write mAction %>" method="post" name="mCdo">
          <p>From: 
            <input name="mFrom" type="text" value="<% response.write mFrom %>" size="50%"/><br />
            To: <input name="mTo" type="text" value="<% response.write mTo %>" size="50%" /> 
            <br />
            Cc: <input name="mCc" type="text" value="<% response.write mCc %>" size="50%" /><br />
            Bcc: <input name="mBcc" type="text" id="mBcc" value="<% response.write mBcc %>" size="50%" /> <br />
            Subject: <input name="mSubject" type="text" value="<% response.write mSubject %>" size="50%" /> <br />
            Email Format: 
            text: <input type="checkbox" name="mTextBody" value="yes" checked="checked" /> 
            html: <input type="checkbox" name="mHtmlBody" value="yes" /><br />
            Text:<br /> <textarea name="mBody" cols="77" rows="10"><% response.write mBody %></textarea> <br /> 
            Remote SMTP: <input name="mSmtp" type="text" value="<% response.write mSmtp %>" />
            Port: <input name="mPort" type="text" value="<% response.write mPort %>" size="5" />
            Timeout: <input name="mTimeout" type="text" value="<% response.write mTimeout %>" size="5" />
            Sec SSL: <input type="checkbox" name="mSsl" value="ture" /> <br />
            Username: <input name="mUser" type="text" value="<% response.write mUser %>" /> <br />
            Password: <input name="mPwd" type="password" value="<% response.write mPwd %>" />  <br />
            SMTP验证选项: 
            <select name="mAuth">
                <option value="0">匿名验证</option>
                <option value="1" selected="selected">普通验证</option>
                <option value="2">NTLM 验证</option>
            </select> 
             邮件发送选项: 
             <select name="mSend">
                <option value="1">Send Using Pickup</option>
                <option value="2" selected="selected">Send Using Port</option>
             </select>
             <br />
            <input type="submit" value="Submit" />   <input type="reset" value="Reset" />
        </form><!-- shawl.qiu code -->
<%     end function %><br />
<a href="?">back</a>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用 Classic ASP 和 SSL 发送电子邮件的示例代码: ``` <% Dim objMail Set objMail = Server.CreateObject("CDO.Message") ' Set up the email configuration objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com" objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "your_email@gmail.com" objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "your_password" objMail.Configuration.Fields.Update ' Set up the email content objMail.To = "recipient_email@example.com" objMail.From = "your_email@gmail.com" objMail.Subject = "Test Email" objMail.TextBody = "This is a test email sent using SSL." ' Send the email On Error Resume Next objMail.Send If Err.Number = 0 Then Response.Write "Email sent successfully." Else Response.Write "An error occurred: " & Err.Description End If Set objMail = Nothing %> ``` 请注意,您需要将上面的代码中的以下行替换为您自己的电子邮件地址和密码: ``` objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "your_email@gmail.com" objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "your_password" objMail.To = "recipient_email@example.com" objMail.From = "your_email@gmail.com" ``` 此外,您需要将 SMTP 服务器和端口设置为您使用的电子邮件服务的设置。在上面的示例中,我们使用 Gmail 的 SMTP 服务器和端口。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值