使用CDO.Message+SMTP来发信

本文介绍了一个使用CDO.Message组件实现的简单邮件发送系统。该系统通过VBScript和JavaScript进行验证及表单处理,利用CDO.Configuration配置邮件服务器参数,并通过CDO.Message发送邮件。
摘要由CSDN通过智能技术生成

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%><head>
<meta http-equiv="Content-Type" content="text/html; charset=" />
<title>CDO.Message邮件系统测试</title>
<script language="JavaScript" type="text/javascript"><!--
function VF_form1(){ //v2.0
<!--start_of_saved_settings-->
<!--type,textarea,name,m_neirong,required,true,errMsg,请填写邮件内容-->
<!--type,text,name,m_zhuzi,required,true,errMsg,请填写邮件的主题-->
<!--type,text,name,m_user,required,true,isEmail,errMsg,对不起.你未填写邮箱地址或邮箱地址不正确-->
<!--end_of_saved_settings-->
   var theForm = document.form1;
   var emailRE = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
   var errMsg = "";
   var setfocus = "";

   if (theForm['m_neirong'].value == ""){
      errMsg = "请填写邮件内容";
      setfocus = "['m_neirong']";
   }
   if (theForm['m_zhuzi'].value == ""){
      errMsg = "请填写邮件的主题";
      setfocus = "['m_zhuzi']";
   }
   if (!emailRE.test(theForm['m_user'].value)){
      errMsg = "对不起.你未填写邮箱地址或邮箱地址不正确";
      setfocus = "['m_user']";
   }
   if (errMsg != ""){
      alert(errMsg);
      eval("theForm" + setfocus + ".focus()");
   }
   else theForm.submit();
}
function TJK_noWayBack(){// www.2581.cn/mxp/ - Thierry Koblentz
history.go(1);
}
TJK_noWayBack();
//-->
</script>
<style type="text/css">
<!--
.td {
   font-family: "宋体";
   font-size: 12px;
   line-height: 25px;
   text-decoration: none;
   color: #000000;
}
-->
</style>
</head>


<div align="center">
<%If (CStr(Request("MM_insert")) = "form1") Then%>
<!--发送代码-->
<%
Const cdoSendUsingMethod="http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSendUsingPort=2
Const cdoSMTPServer="http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort="http://schemas.microsoft.com/cdo/configuration/smtpserverport"
Const cdoSMTPConnectionTimeout="http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
Const cdoSMTPAuthenticate="http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
Const cdoBasic=1
Const cdoSendUserName="http://schemas.microsoft.com/cdo/configuration/sendusername"
Const cdoSendPassword="http://schemas.microsoft.com/cdo/configuration/sendpassword"

Dim objConfig ' As CDO.Configuration
Dim objMessage ' As CDO.Message
Dim Fields ' As ADODB.Fields

Set objConfig = Server.CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields

With Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "SMTP服务器" '改成可用的外部邮件服务器域名
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPConnectionTimeout) = 10
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = "用户名" '以上服务器的用户名
.Item(cdoSendPassword) = "密码" '密码
.Update
End With

Set objMessage = Server.CreateObject("CDO.Message")
Set objMessage.Configuration = objConfig

With objMessage
.To = Trim(Request.Form("m_user")) '改成接收者的邮件地址
.From = "发件人的地址(要和上面的邮件系统相同)" '改成发送人的邮件地址
.Subject = Trim(Request.Form("m_zhuzi")) '标题
.TextBody = Trim(Request.Form("m_neirong")) '正文
'.AddAttachment "C:/Scripts/Output.txt"'邮件附件
.Send
End With

Set Fields = Nothing
Set objMessage = Nothing
Set objConfig = Nothing
%>
<!--发送代码-->
邮件发送成功.
已经送达
<%=trim(Request.Form("m_user"))%>  <a href="mail.asp">返回继续发送</a>
<%else%>

</div>
<form action="<%=MM_editAction%>" method="post" name="form1" onSubmit="VF_form1();return false;">
<table width="713" border="0" align="center" cellpadding="0" cellspacing="0" class="td">
<tr>
<td height="30" align="center">收件人</td>
<td height="30"><input name="m_user" type="text" id="m_user" size="40" /></td>
</tr>
<tr>
<td width="90" height="30" align="center">邮件主题</td>
<td width="245" height="30"><input name="m_zhuzi" type="text" id="m_zhuzi" size="40" /></td>
</tr>
<tr>
<td height="30" align="center">邮件内容</td>
<td height="30"><textarea name="m_neirong" cols="70" rows="15" id="m_neirong"></textarea></td>
</tr>
<tr>
<td height="30" colspan="2" align="center"><input type="hidden" name="MM_insert" value="form1" />
<input type="submit" name="Submit" value=" 发送邮件 " /></td>
</tr>
</table>
</form>
<%end if%>  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值