编写vbs脚本发送邮件

执行vbs脚本文件的程序为: system32文件下的 编写vbs脚本发送邮件

下面vbs脚本代码可以完成用"[email protected]"账号发送一封邮件给"[email protected]"。

  
    
1 NameSpace = " http://schemas.microsoft.com/cdo/configuration/ "
2   Set Email = CreateObject ( " CDO.Message " )
3 Email.From = " [email protected] " ' 发件邮件地址
4   Email.To = " [email protected] " ' 收件邮件地址
5 Email.Subject = " Test_ " + cstr ( now ()) ' 邮件主题
6 Email.Textbody = " OK! It is only a test. " ' 邮件内容
7 Email.AddAttachment " D:\My Documents\My Pictures\809041233006998.jpg " ' 所带附件
8 With Email.Configuration.Fields
9 .Item(NameSpace & " sendusing " ) = 2 ' CDO发送端口号
10 .Item(NameSpace & " smtpserver " ) = " smtp.gmail.com " ' SMTP服务器
11 .Item(NameSpace & " smtpserverport " ) = 465 ' SMTP服务器端口号
12 .Item(NameSpace & " smtpusessl " ) = true ' SMTP服务器是否使用了SSL
13 .Item(NameSpace & " smtpauthenticate " ) = 1 ' 认证方式是BASIC
14 .Item(NameSpace & " sendusername " ) = " [email protected] " ' 发件人邮箱账号
15 .Item(NameSpace & " sendpassword " ) = " ************ " ' 发件人邮箱密码
16 .Update
17 End With
18 Email.Send

 

 

收到的邮件效果图:

编写vbs脚本发送邮件

PS: "smtpserver" "smtpserverport" "smtpusessl" 等信息设置不对时,脚本会弹出错误对话框,以示邮件发送失败。

编写vbs脚本发送邮件

你可能感兴趣的:(发送邮件)