{
CDO.Message oMsg = new CDO.Message()
oMsg.From = ""//发送方邮箱
oMsg.To = ""//接收方邮箱
oMsg.Subject = ""//主题
oMsg.HTMLBody = ""//内容
CDO.IConfiguration iConfg = oMsg.Configuration
ADODB.Fields oFields = iConfg.Fields
oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value=2
oFields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value=""//用户名
oFields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value=""//密码
oFields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value=1
oFields["http://schemas.microsoft.com/cdo/configuration/languagecode"].Value=0x0804
oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value=""//邮件服务器
oFields.Update()
oMsg.BodyPart.Charset="gb2312"
oMsg.HTMLBodyPart.Charset="gb2312"
oMsg.Send()
oMsg = null
}
catch (Exception ex)
{
throw ex
}
Set objMail = Server.CreateObject("CDO.Message") Set objCDO = Server.CreateObject("CDO.Configuration") objCDO.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") =2objCDO.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver")= "smtp.mxhichina.com" '邮件服务器,我这里用的是阿里云objCDO.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25objCDO.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10objCDO.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1objCDO.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "XXX@XXX.com"'发送邮件的邮箱地址objCDO.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "XXX"'密码objCDO.Fields.Update Set objMail.Configuration = objCDOobjMail.From = "XXX@XXX.com"''发件人,这里和上面的发送邮件地址保持一致objMail.Subject = "用户信息" ''标题objMail.To = "aaa@163.com"''收件人objMail.HtmlBody = "邮件正文内容"'发送内容。objMail.SendPrivate Sub Command1_Click()Dim cm As New CDO.Message 'CDO.message是一个发送邮件的对象
'Set cm = CreateObject("CDO.Message") '创建对象 '引用路径:C:\Windows\system32\cdosys.dll'这个是要引用的,如果不引用,可以用这句也行
cm.From = "30687724@qq.com" '设置发信人的邮箱"
cm.To = "suxg@eshinetech.com" '设置收信人的邮箱
cm.Subject = "主题:邮件发送试验" '设定邮件的主题
'cm.TextBody = '邮件正文,使用文本格式发送邮件,如果太复杂了就不行了,要用下面这种
cm.HtmlBody = "邮件发送试验^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" '使用html格式发送邮件
cm.AddAttachment "D:\1.txt" '发的附件名与地址
stUl = "http://schemas.microsoft.com/cdo/configuration/" '微软服务器网址,固定的,不用改的
With cm.Configuration.Fields
.Item(stUl &"smtpserver") = "smtp.qq.com" 'SMTP服务器地址
.Item(stUl &"smtpserverport") = 25 'SMTP服务器端口
.Item(stUl &"sendusing") = 2'发送端口
.Item(stUl &"smtpauthenticate") = 1 '需要提供用户名和密码,0是不提供 '
.Item(stUl &"sendusername") = "30687724"'发送方邮箱名称,不用输入@后面的东西
.Item(stUl &"sendpassword") = "suxi87724" '发送方邮箱密码
.Update
End With
cm.Send '最后当然是执行发送了
Set cm = Nothing
'发送成功后即时释放对象
End Sub
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)