vbs发送邮件代码
NameSpace = " " Set Email = CreateObject("CDO.Message") Email.From = " " Email.To =" " Email.Subject = "say hello" Email.Textbody = " test body " Email.AddAttachment "" With Email.Configuration.Fields .Item(NameSpace&"sendusing") = 2 .Item(NameSpace&"smtpserver") = "smtp.sohu.com" .Item(NameSpace&"smtpserverport") = 25 .Item(NameSpace&"smtpauthenticate") = 1 .Item(NameSpace&"sendusername") = "benio_guo" .Item(NameSpace&"sendpassword") = "q1w2e3" .Update End With Email.Send 下面是 vb版 Private Sub Form_Load() Dim NameS As String Dim Email As Object NameS = "" Set Email = CreateObject("CDO.Message") Email.From = "" Email.To = "" Email.Subject = "say hello" Email.Textbody = "test body" Email.AddAttachment "C:\test.txt" Email.Configuration.Fields.Item(NameS & "sendusing") = 2 Email.Configuration.Fieds.Item(NameS & "smtpserver") = "smtp.sohu.com" Email.Configuration.Fields.Item(NameS & "smtpserverport") = 25 Email.Configuration.Fields.Item(NameS & "smtpauthenticate") = 1 Email.Configuration.Fields.Item(NameS & "sendusername") = "benio_guo" Email.Configuration.Fields.Item(NameS & "sendpassword") = "q1w2e3" Email.Configuration.Fields.Update Email.Send End Sub
|
'把以下文件存为vbs文件,双击就可运行,也可以放到Job里去运行。 Set cdo = CreateObject( "CDO.Message ") strCfg = "http://schemas.microsoft.com/cdo/configuration/ " With cdo .Sender = "发送者邮件地址 " .From = "发送者邮件地址 " .To = "接收者邮件地址 " .Fields( "urn:schemas:mailheader:X-Priority ") = 1 .Fields.Update .Subject = "邮件标题 " .TextBody = "邮件内容 " .Configuration(strCfg & "SendUsing ") = 2 .Configuration(strCfg & "smtpserver ") = "发送邮件服务器地址 " .Configuration(strCfg & "sendusername ") = "发送者邮箱帐号 " .Configuration(strCfg & "sendpassword ") = "发送者邮箱密码 " .Configuration.Fields.Update .send End With msgbox "发送完成 "
NameSpace = "http://schemas.microsoft.com/cdo/configuration/" set Email = CreateObject("CDO.Message") Email.From = "Benio_Guo@cn.*.com" Email.To = "Benio_Guo@cn.*.com" Email.Subject = " Daily Planned Order Report_"&year(now())&month(now())&day(now()) 'x="C:\test.txt" y="K:\ASCP\reports\APS_PLAN_ORDER_FOR_RELEASE_BY_WEEKLY_DR.xls" 'Set fso=CreateObject("Scripting.FileSystemObject") 'Set myfile=fso.OpenTextFile(x,1,Ture) 'c=myfile.readall 'myfile.Close 'Email.Textbody = c Email.AddAttachment y with Email.Configuration.Fields .Item(NameSpace&"sendusing") = 2 .Item(NameSpace&"smtpserver") = "dm01" .Item(NameSpace&"smtpserverport") = 25 .Item(NameSpace&"smtpauthenticate") = 1 .Item(NameSpace&"sendusername") = "benio guo" .Item(NameSpace&"sendpassword") = "*pwd*" .Update end with Email.Send Set Email=Nothing