ASP下使用CDO.Message实现需要身份验证的邮件发送程序(实例代码)
说起这个事挺杯具的!以前做过的发邮件的源码,再次使用就出现了CDO.Message.1 (0×8004020D),很是郁闷的,在公司就使劲用google那个搜啊!又用了百度搜,还是找不原因,真的十分郁闷了!下班回到家,上线qq找到了老哥!问他什么问题,他只是说用cdo很麻烦的说,要不你就用jmail吧!本来打算就此放弃,看到了这篇文章http://www.cnblogs.com/yirlin/archive/2006/11/22/569224.html 我就抱着试试的态度试了一试,果然成功了!具体不知道什么原因造成的!难不成以前的台式机里面的配置很现在的本本的配置不同!程序就运行起来吗?如有高手看到,请指点小弟一二!这问题真的很郁闷的说!
- '这是以前的代码
- sub sendEmail(fromEmail,toEmail,subject,concent)
- Dim MailObject
- Set MailObject = Server.CreateObject("CDO.Message")
- with MailObject
- .From= fromEmail
- .To=toEmail
- .Configuration.Fields.item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mailServer
- .Configuration.Fields.item(" http://schemas.microsoft.com/cdo/configuration/sendusername")= mailUser
- .Configuration.Fields.item(" http://schemas.microsoft.com/cdo/configuration/sendpassword")= mailPwd
- '.Configuration.Fields.item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")="1"
- .Configuration.Fields.item("http://schemas.microsoft.com/cdo/configuration/languagecode")="0x0804"
- .Configuration.Fields.Update
- .MimeFormatted = 1
- .Subject=subject
- .HtmlBody=concent
- .BodyPart.Charset = "gb2312"
- .HtmlBodyPart.Charset = "gb2312"
- .Send
- end with
- set MailObject=Nothing
- end sub
- '这是现在用的!
- Set objMail = Server.CreateObject("CDO.Message")
- Set objConfig = Server.CreateObject ("CDO.Configuration")
- objConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
- objConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
- objConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.mail.com"
- objConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
- objConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"
- objConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
- objConfig.Fields("http://schemas.microsoft.com/cdo/configuration/languagecode") = "0x0804"
- objConfig.Fields.Update()
- Set objMail.Configuration = objConfig
- objMail.Subject = "Mail Subject"
- objMail.From = chr(34) & "姓名" & chr(34) & "username@mail.com"
- objMail.To = "gbhglxs@customs.gov.cn"
- objMail.HTMLBody = "Mail Body"
- objMail.AddAttachment(http://xxxxxx/xxxx.xxx) '或者其他任何正确的url,包括http,ftp,file等等。
- objMail.Send
- Response.Write "邮件发送成功!"
- 最值得注意的是:sendusername要和From相一致。

















