1 Sub SendMail(pMailFrom, pMailTo, pSubject, pMailBody, pMailSmtpServer) 2 On Error Resume Next 3 Dim objShell 4 Dim oMsg 5 6 Set objShell = CreateObject("Wscript.Shell") 7 Set oMsg = CreateObject("CDO.Message") 8 9 oMsg.From = pMailFrom & " <" & pMailFrom & ">" '送信人 10 oMsg.To = pMailTo & " <" & pMailTo & ">" '收件人 11 oMsg.Subject = pSubject '标题 12 oMsg.HtmlBody = pMailBody '邮件正文(HTML格式) 13 'oMsg.TextBody = pMailBody '邮件正文(文本格式) 14 15 oMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 16 oMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = pMailSmtpServer 'ExChange邮件服务器名 17 oMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 18 oMsg.Configuration.Fields.Update 19 20 oMsg.Send 21 If Err.Number <> 0 Then 22 AddLog ("送信失败:" & Err.Description) 23 WScript.Quit -1 24 End If 25 26 Set oMsg = Nothing 27 Set objShell = Nothing 28 End Sub