ASP中通过需要认证的SMTP服务器发送邮件

本文介绍了一种使用ASP脚本语言结合CDO组件来发送经过身份验证的SMTP邮件的方法。通过设置CDO.Configuration的各项参数,如SMTP服务器地址、登录名和密码等,实现了从指定邮箱发送HTML格式邮件的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

仿照上文《.Net中通过需要认证的SMTP服务器发送邮件》,将代码修改一下,就可以用ASP实现需要验证SMTP服务器邮件的发送,代码如下:

mail.asp
<%
if request.Form("Submit")<>"" then
Dim msg
Dim config
Dim ofields

set msg = Server.CreateObject("CDO.Message")
set config = Server.CreateObject("CDO.Configuration")
set ofields = config.Fields


With ofields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "用户名"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "密码"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/languagecode") = "0x0804"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.163.com" 
'可以换成别的,跟".From "里的地址对应就可以了
.Update
End With

With msg
Set .Configuration = config
.From = "用户名@163.com"
.To = request.Form("to")
.Subject = request.Form("subject")
.HTMLBody = "<html><body>"&request.Form("body")&"</html></body>"
.Send
End With

Set msg = Nothing
Set config = Nothing
Set ofields = Nothing

Response.Write("<script>alert('发送成功!');location.href='mail.asp';</script>")

else
%>
<html>
<head>
<title>发送邮件测试</title>
</head>
<body>
<form name="form1" method="post" action="mail.asp">
  <table width="500" border="0">
    <tr>
      <td width="69" height="30">收信人</td>
      <td width="421"><input name="to" type="text" id="to"></td>
    </tr>
    <tr>
      <td height="30">主题</td>
      <td><input name="subject" type="text" id="subject"></td>
    </tr>
    <tr>
      <td height="30">正文</td>
      <td><textarea name="body" cols="55" rows="8" id="body"></textarea></td>
    </tr>
    <tr>
      <td height="30" colspan="2" align="center"><input type="submit" name="Submit" value="发送"></td>
    </tr>
  </table>
</form>
</body>
</html>
<%end if%>

(本人电脑上测试通过)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值