windows下简单的vbscript自动发送邮件--带附件

1.设置cscript为指定编译器:

    在dos中执行: cscript //h:cscript //s

 

2. 在记事本中编写vbs脚本,另存为 sendmail.vbs, 内容如下:

Set objEmail = CreateObject("CDO.Message")

Call SendMail()

Sub SendMail
        objEmail.From = "[email protected]" '发件人
        objEmail.To = "[email protected]" '收件人
        objEmail.Subject = "邮件主题" '电子邮件主题主题
        objEmail.Textbody = "电子邮件内容" '电子邮件内容
        objEmail.AddAttachment "c:\附件.txt" 
        objEmail.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        objEmail.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.163.com" 'SMTP服务器地址
        objEmail.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "xxx" '用户名
        objEmail.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "xxx" '密码
        objEmail.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 '明文验证
        objEmail.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 'SMTP端口号
        objEmail.Configuration.Fields.Update
        objEmail.Send
End Sub

3. 在记事本中编写bat脚本,另存为 sendmail.bat, 内容如下:

     call automail.vbs

 

4. 可用windows定时任务来调用sendmail.bat.

你可能感兴趣的:(windows下简单的vbscript自动发送邮件--带附件)