ASP用CDO.Message发送邮件

ASP用CDO.Message发送邮件

http://www.szasp.cn/HTML/30/31/2007/14670.html

<%
function send_mail(s_email,s_email2,s_topic,s_body)

'参数说明
's_email:  主要邮件地址
's_email2: 备用邮件地址
's_topic:  邮件主题
's_body:   邮件内容

dim eAccount,vTmp,iConf,Flds,oMail
   
  eAccount = "test@smtp.126.com" '这里是你的邮件服务器地址和登陆名,我用的是126的邮箱做的测试

    vTmp = Split(eAccount, "@", -1, vbTextCompare)

    Set iConf = server.CreateObject("CDO.Configuration")
    Set Flds = iConf.Fields
    Flds("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'cdoSendUsingPort这里是发送邮件端口
    Flds("http://schemas.microsoft.com/cdo/configuration/smtpserver") = vTmp(1)
    Flds("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 '这里是SMTP服务器端口
    Flds("http://schemas.microsoft.com/cdo/configuration/smtpaccountname") = eAccount
    Flds("http://schemas.microsoft.com/cdo/configuration/sendemailaddress") = eAccount
    Flds("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'cdoBasic
    Flds("http://schemas.microsoft.com/cdo/configuration/sendusername") = vTmp(0)
    Flds("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "xxxxxx"   '我的126邮箱密码
    Flds.Update

    set oMail = server.CreateObject("CDO.Message")
    oMail.To = s_email
 If s_email2<>"" Then
 oMail.CC = s_email2
 End If
    oMail.Subject = s_topic     
    oMail.HTMLBody = s_body
    oMail.From = "test@126.com"    '这里必须和上面的登陆名一致
    

    Set oMail.Configuration = iConf
    oMail.MimeFormatted = True
    oMail.AutoGenerateTextBody = True
    oMail.Fields.Update
    oMail.HTMLBodyPart.Charset = "gb2312"
    oMail.Send

    Set oMail = Nothing    
    Set Flds = Nothing
    Set iConf = Nothing
     
  send_mail=true  
  if err then
    err.clear
    send_mail=false
  end if
end function

If send_mail(test@163.com","test2@163.com","邮件主题","邮件内容")=true Then
 '发送成功
Else
 '发送失败
End If
%>


另一篇

 

 

How to send HTML formatted mail using CDO for Windows 2000 and a remote SMTP service

http://support.microsoft.com/kb/286431

<script type="text/javascript">function loadTOCNode(){}</script>
Article ID:286431
Last Review:August 25, 2005
Revision:3.1
This article was previously published under Q286431

SUMMARY

<script type="text/javascript">loadTOCNode(1, 'summary');</script>
This article describes how to send HTML formatted mail using CDO for Windows 2000 (CDOSYS) or CDO for Exchange 2000 (CDOEX) using a remote computer's SMTP service.

Back to the top

MORE INFORMATION

<script type="text/javascript">loadTOCNode(1, 'moreinformation');</script>
1.
'  Send by connecting to port 25 of the SMTP server.
Dim  iMsg 
Dim  iConf 
Dim  Flds 
Dim  strHTML

Const  cdoSendUsingPort  =   2

set  iMsg  =   CreateObject ( " CDO.Message " )
set  iConf  =   CreateObject ( " CDO.Configuration " )

Set  Flds  =  iConf.Fields

'  Set the CDOSYS configuration fields to use port 25 on the SMTP server.

With  Flds
    .Item(
" http://schemas.microsoft.com/cdo/configuration/sendusing " =  cdoSendUsingPort
    
' ToDo: Enter name or IP address of remote SMTP server.
    .Item( " http://schemas.microsoft.com/cdo/configuration/smtpserver " =   " <remote SMTP server> "  
    .Item(
" http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout " =   10   
    .Update
End   With

'  Build HTML for message body.
strHTML  =   " <HTML> "
strHTML 
=  strHTML  &   " <HEAD> "
strHTML 
=  strHTML  &   " <BODY> "
strHTML 
=  strHTML  &   " <b> This is the test HTML message body</b></br> "
strHTML 
=  strHTML  &   " </BODY> "
strHTML 
=  strHTML  &   " </HTML> "

'  Apply the settings to the message.
With  iMsg
    
Set  .Configuration  =  iConf
    .To 
=   " <email address> "   ' ToDo: Enter a valid email address.
    .From  =   " <email address> "   ' ToDo: Enter a valid email address.
    .Subject  =   " This is a test CDOSYS message (Sent via Port 25) "
    .HTMLBody 
=  strHTML
    .Send
End   With

'  Clean up variables.
Set  iMsg  =   Nothing
Set  iConf  =   Nothing
Set  Flds  =   Nothing

MsgBox   " Mail Sent! "
2.Edit the sections of the code that are marked "ToDo".
3.Save the file, and then double-click it.

The code creates an HTML-formatted message and sends it using the remote computer's SMTP service.

Back to the top

REFERENCES

<script type="text/javascript">loadTOCNode(1, 'references');</script>
For additional information, click the article number below to view the article in the Microsoft Knowledge Base:
286430 (http://support.microsoft.com/kb/286430/EN-US/) How To Send HTML Formatted mail Using CDO for Windows 2000 and the Local Pickup Directory
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 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、付费专栏及课程。

余额充值