|
楼上达人,学习了:)
Function SendMail(mailFrom,mailSmtp,sendUserName,sendUserPassword,mailTo,mailSubject,mailBody,mailAttachment)
Const conSendUsing ="http://schemas.microsoft.com/cdo/configuration/sendusing"
Const conServer ="http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const conServerPort ="http://schemas.microsoft.com/cdo/configuration/smtpserverport"
Const conConnectionTimeout ="http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
Const conAuthenticate ="http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
Const conUsessl ="http://schemas.microsoft.com/cdo/configuration/smtpusessl"
Const conSendUserName ="http://schemas.microsoft.com/cdo/configuration/sendusername"
Const conSendPassword ="http://schemas.microsoft.com/cdo/configuration/sendpassword"
Set objMessage = CreateObject("CDO.Message")
Set objConfig = CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields
Set objMessage.Configuration = objConfig
With Fields
.Item(conSendUsing) = 2 '2为使用外部SMTP服务器,不要更改
.Item(conServer) = mailSmtp '改成可用的外部邮件服务器域名
.Item(conServerPort) = 25 '外部SMTP服务器端口,gmail使用465,其它一般使用25
.Item(conConnectionTimeout) = 20 '设定连接超时,单位秒
.Item(conUsessl) = False '是否使用SSL安全套接字,gmail为true,其它一般false
.Item(conAuthenticate) = 1 '1为发送邮件需要认证,通常不要更改
.Item(conSendUserName) = sendUserName
.Item(conSendPassword) = sendUserPassword
.Update
End With
With objMessage
.To = Trim(mailTo) '改成接收者的邮件地址
.From = mailFrom '改成发送人的邮件地址,要和上面的邮件系统相同
.Subject = Trim(mailSubject) '标题
.HTMLBody = "<html><head><meta http-equiv=""Content-Type"" content=""text/html; charset=Shift_JIS"" /></head>"&_
"<body>"&mailBody&"</body></html>" 'HTML邮件正文
.HTMLBodyPart.Charset="Shift_JIS" '//邮件HTML格式编码
If Trim(mailAttachment) <> "" Then
.AddAttachment mailAttachment '邮件附件
End If
.Send
End With
Set objMessage = Nothing
Set objConfig = Nothing
End Function |
|