0

我想批量发送电子邮件,但由于 mailto 命令不会在没有我单击发送按钮的情况下通过 Outlook 发送电子邮件。

我在网上找到了这个 VBS 脚本,它无需人工交互即可发送电子邮件。

我只需要帮助电话或者是否可以将 VBS 嵌入到 BATCH 文件中。

' Create email object
Set oolApp = CreateObject("Outlook.Application")
Set email = oolApp.CreateItem(0)
email.Recipients.Add("myemail@esomeemail.com")

' Create the body of the email
MailBody = "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD W3 HTML//EN"">"
MailBody = MailBody & "<HTML>" & vbcrlf
MailBody = MailBody & "<HEAD><TITLE>No Invoices</TITLE></HEAD>"
MailBody = MailBody & "<BODY>" & vbcrlf
MailBody = MailBody & "<B>For Your Information</B>,<BR><BR>"
MailBody = MailBody & "No invoices were issued today.<BR><BR>"
MailBody = MailBody & "</BODY></HTML>"

' Send the Email
email.Subject = "No Invoices Issued"
email.HTMLBody = MailBody
email.Send
4

1 回答 1

2

编辑:现在我重新阅读了你的问题,我不确定你在问什么。您是在问如何运行 vbscript 吗?只需将其保存filename.vbs并执行它

cscript filename.vbs

(或者cscript /nologo filename.vbs如果您想避免显示 Microsoft 的 cscript 虚荣垃圾邮件)。


另一方面,如果您想将其合并到批处理脚本中,那么有很多方法可以将批处理脚本中的内容回显到外部文件。大多数人只是做类似的事情

echo Set oolApp = CreateObject^("Outlook.Application"^)>> vbsfile

或类似的,^根据需要转义。但是,您可能会发现此页的 heredoc 方法很有用。这是使用我昨天帮助您制作的脚本的示例:

@if (@X)==(@Y) @end /* (batch + jscript hybrid script init)

:: *** Batch script *****

@echo off
setlocal enabledelayedexpansion

set recipient=myemail@esomeemail.com

for /f "delims=" %%I in ('wget "%~1" -O- -q 2^>NUL ^| findstr /i "last.*updated.*as.*of"') do (
    for /f "delims=" %%x in ('cscript /nologo /e:jscript "%~f0" "%%I"') do (
        set /a "thirtyMinutes = 30 * 60 * 1000"
        if %%x GEQ !thirtyMinutes! (
            call :doEmail
        )
    )
    exit /b
)
exit /b

:doEmail
call :heredoc vbs >email.vbs && goto endvbs
' Create email object
Set oolApp = CreateObject("Outlook.Application")
Set email = oolApp.CreateItem(0)
email.Recipients.Add("!recipient!")

' Create the body of the email
MailBody = "<^!DOCTYPE HTML PUBLIC ""-//W3C//DTD W3 HTML//EN"">"
MailBody = MailBody & "<HTML>" & vbcrlf
MailBody = MailBody & "<HEAD><TITLE>No Invoices</TITLE></HEAD>"
MailBody = MailBody & "<BODY>" & vbcrlf
MailBody = MailBody & "<B>For Your Information</B>,<BR><BR>"
MailBody = MailBody & "No invoices were issued today.<BR><BR>"
MailBody = MailBody & "</BODY></HTML>"

' Send the Email
email.Subject = "No Invoices Issued"
email.HTMLBody = MailBody
email.Send
:endvbs

cscript /nologo email.vbs
del email.vbs
goto :EOF

:: https://stackoverflow.com/a/15032476/1683264
:heredoc <uniqueIDX>
setlocal enabledelayedexpansion
set go=
for /f "delims=" %%A in ('findstr /n "^" "%~f0"') do (
    set "line=%%A" && set "line=!line:*:=!"
    if defined go (if #!line:~1!==#!go::=! (goto :EOF) else echo(!line!)
    if "!line:~0,13!"=="call :heredoc" (
        for /f "tokens=3 delims=>^ " %%i in ("!line!") do (
            if #%%i==#%1 (
                for /f "tokens=2 delims=&" %%I in ("!line!") do (
                    for /f "tokens=2" %%x in ("%%I") do set "go=%%x"
                )
            )
        )
    )
)
goto :EOF

:: *** JScript script *****/
var args = [];
for (var i=0; i<WScript.arguments.length; i++) { args.push(WScript.arguments(i)) }
var t = args.join(' ').replace(/^\s+|<[^>]+>|\s+$/g,'').replace(/\&nbsp;/g, ' ').split(' ');
var h = t[4].split(':')[0];
if (/pm/i.test(t[5])) h = h * 1 + 12;
var ds = t[6] + ' ' + t[7] + ', ' + new Date().getFullYear() + ' ' + h + ':' + t[4].split(':')[1];
var diff = new Date() - new Date(ds);
WScript.echo(diff);

我没有对此进行测试,但请尝试一下,看看您的想法。

于 2013-03-13T14:36:45.020 回答