【问题标题】:VB script to send emails - Wait until email is send用于发送电子邮件的 VB 脚本 - 等到发送电子邮件
【发布时间】:2014-01-23 19:17:03
【问题描述】:

我使用下面的 VB 脚本来发送电子邮件。当我从命令提示符执行它时,它会在执行后返回到命令提示符。如果发送时出现任何错误,则会显示一条弹出消息。

If WScript.Arguments.Count <> 6 then
 Wscript.Echo "Missing parameters"
Else
 Set objMessage = CreateObject("CDO.Message")
 objMessage.Subject = Wscript.Arguments(0) 
 objMessage.From = Wscript.Arguments(1) 
 objMessage.To = Wscript.Arguments(2) 
 objMessage.TextBody = Wscript.Arguments(3)
 objMessage.AddAttachment Wscript.Arguments(4)
 objMessage.AddAttachment Wscript.Arguments(5)
 objMessage.Configuration.Fields.Item _
 ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
 objMessage.Configuration.Fields.Item _
 ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp server ip"
 objMessage.Configuration.Fields.Item _
 ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
 objMessage.Configuration.Fields.Update
 objMessage.Send
End If

我想知道在程序中发送邮件和获取objMessage.Send的状态需要多少时间。

我想使用 Wscript.Echo “错误消息”来显示错误。上面的代码需要做哪些修改,以便执行等到邮件发送成功,然后显示消息。

提前致谢。 阿肖克

【问题讨论】:

    标签: email vbscript


    【解决方案1】:

    Send 同步运行,即它只返回 if

    • 发生错误
    • SMTP 服务器拒绝了邮件
    • SMTP 服务器接受了要传递的邮件

    Send启用错误处理并检查是否发生错误:

    On Error Resume Next
    objMessage.Send
    If Err Then
      WScript.Echo Err.Number & vbTab & Err.Description
    Else
      WScript.Echo "Success"
    End If
    On Error Goto 0
    

    【讨论】:

      猜你喜欢
      • 2011-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-06
      • 1970-01-01
      • 1970-01-01
      • 2012-09-12
      • 2020-11-03
      相关资源
      最近更新 更多