VB脚本发送邮件 [英] VB script for send mail

查看:230
本文介绍了VB脚本发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有关于VB脚本知识。所以自寻这里请帮我... :)
我们有一个备份批处理脚本使用的机器人复制所有数据复制到另一台服务器。
我们安排了剧本,但所有的时间,我们必须去该服务器并手动该脚本运行或不检查。
现在我们写一个VB脚本,将调用批处理脚本,并检查脚本运行正常,如果脚本正常运行,然后邮寄会来备份完成备份其他未完成。
如果您有任何关于VB脚本任何想法,请帮助我。

I dont have knowledge about vb scripting. so m asking here please help me... :) we have one backup batch script which copy all data to another server using robo copy. we schedule that script, but all the time we have to go that server and check manually that script run or not. now we have write one vb script that will call that batch script and check that script run properly if script run properly then mail will come as backup completed else backup is not completed. please if you have any idea about vb script please help me.

推荐答案

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

Here's a batch file that uses VBS to send an email.

阅读剧本的意见,看看如何对它进行测试。

Read the comments in the script to see how to test it.

:: 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

这篇关于VB脚本发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆