用于发送邮件的VB脚本

时间:2014-04-11 10:30:38

标签: email batch-file vbscript

我对vb脚本没有了解。所以问这里请帮帮我...... :) 我们有一个备份批处理脚本,它使用机器人副本将所有数据复制到另一个服务器。 我们安排该脚本,但我们必须一直去那个服务器并手动检查该脚本是否运行。 现在我们编写了一个vb脚本,它将调用该批处理脚本并检查脚本是否正常运行,如果脚本正常运行,那么邮件将作为备份完成,否则备份未完成。 如果您对vb脚本有任何了解,请帮助我。

2 个答案:

答案 0 :(得分:0)

你可以使用mailsend.exe,只需将exe文件放在你的脚本文件夹&最后将下面的代码附加到RoboCopy脚本中。如果你不想要cc或bcc任何人,只需添加+ cc& + BCC

输入logs.txt | mailsend.exe -smtp smtp_server_ip_or_FQDN -port 25 -d smtp.mail.com -t xyz@mail.com -f seding_from@mail.com -sub"无论主题是什么" -user mail_username@mail.com -pass mailpassword -auth -cc xyz@mail.com -bcc xyz@mail.com

答案 1 :(得分:0)

这是一个使用VBS发送电子邮件的批处理文件。

阅读脚本中的注释,了解如何测试它。

:: email.bat :::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal

:: use these settings to send from a gmail account
:: set port=465 and set SSL=True

:: use these settings for standard email SMTP port and no encryption
:: set port=25 and set SSL=False

:: Change these following items to use the same variables all the time
:: or use the command line to pass all the variables

set Port=25
set SSL=False
set From="myemail@myemailserver.com"
set To="recipient@server.com"
set Subject="Subject line"
set Body="Email Body in one line"
set SMTPServer="mailservername.myemailserver.com"
set User="username"
set Pass="password"
set fileattach="d:\myfolder\file.txt"


:: This section sets the command line arguments
:: use this format:  CALL email.bat "myname@gmail.com" "RecipientEmailAddress@server.com" "Subject line" "Email Body in one line" "smtp.gmail.com"  "myname@gmail.com" "password" "d:\folder\filename to attach.txt"


if "%~7" NEQ "" (
set From="%~1"
set To="%~2"
set Subject="%~3"
set Body="%~4"
set SMTPServer="%~5"
set User="%~6"
set Pass="%~7"
set fileattach="%~8"
)

set "vbsfile=%temp%\email-bat.vbs"
del "%vbsfile%" 2>nul
set cdoSchema=http://schemas.microsoft.com/cdo/configuration
echo >>"%vbsfile%" Set objArgs       = WScript.Arguments
echo >>"%vbsfile%" Set objEmail      = CreateObject("CDO.Message")
echo >>"%vbsfile%" objEmail.From     = %From%
echo >>"%vbsfile%" objEmail.To       = %To%
echo >>"%vbsfile%" objEmail.Subject  = %Subject%
echo >>"%vbsfile%" objEmail.Textbody = %body%
if exist %fileattach% echo >>"%vbsfile%" objEmail.AddAttachment %fileattach%
echo >>"%vbsfile%" with objEmail.Configuration.Fields
echo >>"%vbsfile%"  .Item ("%cdoSchema%/sendusing")        = 2 ' not local, smtp
echo >>"%vbsfile%"  .Item ("%cdoSchema%/smtpserver")       = %SMTPServer%
echo >>"%vbsfile%"  .Item ("%cdoSchema%/smtpserverport")   = %port%
echo >>"%vbsfile%"  .Item ("%cdoSchema%/smtpauthenticate") = 1 ' cdobasic
echo >>"%vbsfile%"  .Item ("%cdoSchema%/sendusername")     = %user%
echo >>"%vbsfile%"  .Item ("%cdoSchema%/sendpassword")     = %pass%
echo >>"%vbsfile%"  .Item ("%cdoSchema%/smtpusessl")       = %SSL%
echo >>"%vbsfile%"  .Item ("%cdoSchema%/smtpconnectiontimeout") = 30
echo >>"%vbsfile%"  .Update
echo >>"%vbsfile%" end with
echo >>"%vbsfile%" objEmail.Send

cscript.exe /nologo "%vbsfile%"
echo email sent (if variables were correct)
del "%vbsfile%" 2>nul
goto :EOF