Colorful Life2010

使用CDO.Message组件在线发送邮件
Weather:晴 ,北风 4-5级 ,最低气温2 ℃

以下为asp版本,组件都是相同的,使用语言不同,最多改一下里面的变量声明方法即可,通常此组件是用来在.net环境下发邮件用的.

sub CdoMail()
 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) = "mail.3rgb.com" '改成可用的外部邮件服务器域名
  .Item(cdoSMTPServerPort) = 25
  .Item(cdoSMTPConnectionTimeout) = 10
  .Item(cdoSMTPAuthenticate) = cdoBasic
  .Item(cdoSendUserName) = "[email protected]" '以上服务器的用户名
  .Item(cdoSendPassword) = "12456" '密码
  .Update
 End With

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

 With objMessage
  .BodyPart.Charset = "Shift_JIS"  '//邮件编码
  .HTMLBodyPart.Charset="Shift_JIS" '//邮件HTML格式编码
  .To = "[email protected]" '改成接收者的邮件地址
  .From = "[email protected]" '改成发送人的邮件地址,最好同服务器登录地址一样
  .Subject = "邮件标题" '标题
  .HTMLBody = "<html><head><meta http-equiv=""Content-Type"" content=""text/html; charset=Shift_JIS"" /></head><body>邮件内容</body></html>" 'HTML邮件正文
  .TextBody = "邮件内容" '纯文本正文
  .AddAttachment "C:\Scripts\Output.txt" '邮件附件
  .Send
 End With

 Set Fields = Nothing
 Set objMessage = Nothing
 Set objConfig = Nothing
end sub

 

更多内容请参考:http://msdn.microsoft.com/library/CHS/dntaloc/html/introcdoexch2k.asp

历史上的今天: [2010/03/25]苹果分箱问题
[2005/03/25]打开显示器看电视,明天开始看《马大帅》

[使用CDO.Message组件在线发送邮件]的回复

Post a Comment~