ASP下使用CDO.Message实现需要身份验证的邮件发送程序(实例代码)

2010/06/07  |  23:41分类:生活琐事!  |  标签:  |  49

说起这个事挺杯具的!以前做过的发邮件的源码,再次使用就出现了CDO.Message.1 (0×8004020D),很是郁闷的,在公司就使劲用google那个搜啊!又用了百度搜,还是找不原因,真的十分郁闷了!下班回到家,上线qq找到了老哥!问他什么问题,他只是说用cdo很麻烦的说,要不你就用jmail吧!本来打算就此放弃,看到了这篇文章http://www.cnblogs.com/yirlin/archive/2006/11/22/569224.html 我就抱着试试的态度试了一试,果然成功了!具体不知道什么原因造成的!难不成以前的台式机里面的配置很现在的本本的配置不同!程序就运行起来吗?如有高手看到,请指点小弟一二!这问题真的很郁闷的说!

  1. '这是以前的代码
  2. sub sendEmail(fromEmail,toEmail,subject,concent)
  3.  
  4. Dim MailObject
  5.  
  6. Set MailObject = Server.CreateObject("CDO.Message")
  7.  
  8. with MailObject
  9.     .From= fromEmail
  10.     .To=toEmail
  11.         .Configuration.Fields.item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mailServer
  12.         .Configuration.Fields.item(" http://schemas.microsoft.com/cdo/configuration/sendusername")= mailUser
  13.         .Configuration.Fields.item(" http://schemas.microsoft.com/cdo/configuration/sendpassword")= mailPwd
  14.         '.Configuration.Fields.item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")="1"
  15.         .Configuration.Fields.item("http://schemas.microsoft.com/cdo/configuration/languagecode")="0x0804"
  16.         .Configuration.Fields.Update
  17. .MimeFormatted = 1
  18.         .Subject=subject
  19.         .HtmlBody=concent
  20.         .BodyPart.Charset = "gb2312"
  21.         .HtmlBodyPart.Charset = "gb2312"
  22.         .Send
  23. end with
  24. set MailObject=Nothing 
  25. end sub
  1. '这是现在用的!
  2. Set objMail = Server.CreateObject("CDO.Message")
  3. Set objConfig = Server.CreateObject ("CDO.Configuration")
  4. objConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
  5. objConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  6. objConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.mail.com"
  7. objConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
  8. objConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"
  9. objConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
  10. objConfig.Fields("http://schemas.microsoft.com/cdo/configuration/languagecode") = "0x0804"
  11. objConfig.Fields.Update()
  12. Set objMail.Configuration = objConfig
  13. objMail.Subject = "Mail Subject"
  14. objMail.From = chr(34) & "姓名" & chr(34) & "username@mail.com"
  15. objMail.To = "gbhglxs@customs.gov.cn"
  16. objMail.HTMLBody = "Mail Body"
  17. objMail.AddAttachment(http://xxxxxx/xxxx.xxx) '或者其他任何正确的url,包括http,ftp,file等等。
  18. objMail.Send
  19. Response.Write "邮件发送成功!"
  20. 最值得注意的是:sendusername要和From相一致。
喜欢本文,那就收藏到: Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网

发表您的评论