2

我希望 Outlook 每 30 分钟实时向服务器发送一次电子邮件。有没有办法我可以在这个当前代码或通过批处理文件中做到这一点?制作计划任务不可用且没有第三方软件

set objOutlook = CreateObject( "Outlook.Application" )
set objMail = objOutlook.CreateItem(0)

strMessage = "Test"

ON ERROR RESUME NEXT
With objMail
    .From = "email"
    .To = "email"
    .Subject = "Test"
    .Body = strMessage
    .Save
end with

objMail.OriginatorDeliveryReportRequested = True
objMail.Display
objMail.Send

WScript.quit
4

2 回答 2

4

使用 VBScript 休眠的示例:

Dim waittime : waittime = 30 * 60 * 1000    

do 

    ' Insert your code here

    WScript.Sleep(waittime)
loop

哦,去掉 WScript.Quit 语句,这将......退出你的脚本!

编辑

另一种实现它集成消息框的方法是使用WshShell.Popup

do

    ' Insert your code here

    Set WshShell = CreateObject("WScript.Shell")
    If WshShell.Popup ( "Sending a mail every 30 minutes" & vbNewLine & _
                        "Press Cancel to stop or OK to send a mail right now.", _
                            waittime, "Automatic mail sender", 1 or 32 or 4096) = 2  Then
        exit do
    end if

loop

此代码段将每隔 1 次执行一次代码waittime,当按下取消按钮时它会停止,当按下时它会立即执行代码OK

于 2012-11-06T13:40:52.860 回答
2

在 vbs 中使用 while true 循环(首选),或者在批处理文件中使用循环(肮脏的方式)。

:back
myscript.vbs
ping -n 1800 localhost >nul 2>nul 
REM ping -n is a dirty way of sleeping for system <= winxp
REM for win7+ systems, use command `timeout 1800`
goto back

脚本方法:

while true
    set objOutlook = CreateObject( "Outlook.Application" )
    set objMail = objOutlook.CreateItem(0)

    strMessage = "Test"

    ON ERROR RESUME NEXT
    With objMail
        .From = "email"
        .To = "email"
        .Subject = "Test"
        .Body = strMessage
        .Save
    end with

    objMail.OriginatorDeliveryReportRequested = True
    objMail.Display
    objMail.Send
    wscript.sleep(30*60*1000)
wend
于 2012-11-06T13:24:51.343 回答