VBS通过SMTP发送邮件

来源:互联网 发布:三国志9y优化伴侣 编辑:程序博客网 时间:2024/05/16 01:46

 

mfrom="abcd@abcd.com"rcpt="abcd@abcd.com, abcd@abcd.com"attachfile=nullserverip="smtp.abcd.com"sbj="Subject"tbody="Hello World"Call SendMail(mfrom,rcpt,sbj,tbody,attachfile,serverIP)

 

Sub SendMail (mfrom,rcpt,sbj,tbody,attachfile,serverIP)'######### call SendMail (mfrom,rcpt,cc,sbj,tbody,serverIP) ##################'Use external smtp server to send mailif trim(rcpt) = "" or trim(mfrom) = "" then        exit subend ifOn Error Resume Next  Set objEmail = CreateObject("CDO.Message")  objEmail.From = mfrom  objEmail.To = rcpt'  objEmail.Cc = cc'  objEmail.Bcc = bcc  objEmail.Subject = sbj  objEmail.Textbody = tbody'Sending an HTML e-mail:'  objEmail.HTMLBody = "This is a message."'Sending an HTML e-mail that sends a webpage from a website:'  objEmail.CreateMHTMLBody "file://c:/mydocuments/test.htm"  If Trim(attachfile) <> "" Then objEmail.AddAttachment attachfile  objEmail.Configuration.Fields.Item _   ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2  objEmail.Configuration.Fields.Item _   ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = serverIP  objEmail.Configuration.Fields.Item _   ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25'-------Type of authentication, NONE, Basic (Base64 encoded), NTLM--------'objEmail.Configuration.Fields.Item _'("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic'-------Your UserID/Passwd on the SMTP server for SMTP auth for mail sent-----'objEmail.Configuration.Fields.Item _'("http://schemas.microsoft.com/cdo/configuration/sendusername") = "USER_NAME"'objEmail.Configuration.Fields.Item _'("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "PASSWORD"'-------Use SSL for the connection (False or True)---------'objEmail.Configuration.Fields.Item _'("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False'Connection Timeout in seconds (the maximum time CDO will try to establish a'--------connection to the SMTP server)---------'objEmail.Configuration.Fields.Item _'("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60  objEmail.Configuration.Fields.Update  objEmail.Send  set objEmail=nothingEnd Sub

 

原创粉丝点击