【问题标题】:Check outlook send email检查outlook发送邮件
【发布时间】:2016-09-22 03:03:30
【问题描述】:

我的第一个 VBS 脚本需要帮助。基本上我想检查outlook是否打开,如果没有我想打开程序,如果/当它打开时我想发送电子邮件。

 set service = GetObject ("winmgmts:")

for each Process in Service.InstancesOf ("Win32_Process")
    If Process.Name = "outlook.exe"(
        goto "send"
        ) else (
         goto "Open"
         )
    End If
Open:
    Dim objShell
    Set objShell = WScript.CreateObject( "WScript.Shell" )
    objShell.Run("""C:\Program Files (x86)\Microsoft Office\Office16\OUTLOOK.EXE""")
    Set objShell = Nothing
    GOTO send
send:
    wscript.Set objMessage = CreateObject("CDO.Message")
        objMessage.Subject = "Sign in- please reply!"
        objMessage.Sender = "test@gmail.com"
        objMessage.From = "test@gmail.com"
        objMessage.To = "test@gmail.com"
        objMessage.TextBody = Test Body Email
        '==This section provides the configuration information for the remote SMTP server.
        '==Normally you will only change the server name or IP.
        objMessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        'Name or IP of Remote SMTP Server
        objMessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
        'Server port (typically 25)
        objMessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        objMessage.Configuration.Fields.Update
        '==End remote SMTP server configuration section==
        objMessage.Send
        exit

我确实知道我的电子邮件部分可以运行,因为我可以运行它并发送我的电子邮件。我在使用“If, ELSE, THEN”语句时遇到问题。

【问题讨论】:

    标签: vbscript


    【解决方案1】:
    If Process.Name = "outlook.exe" Then
        send
    Else
        open    
    End If
    

    将是 If..Then..Else 的正确格式,但 vbscript 不支持 GoTo 语句。如果您将 send 和 open 转换为函数,那么您将能够如上所示调用它们

    【讨论】:

      猜你喜欢
      • 2017-08-29
      • 1970-01-01
      • 2020-05-21
      • 1970-01-01
      • 2017-05-25
      • 1970-01-01
      • 1970-01-01
      • 2014-04-14
      • 2010-09-25
      相关资源
      最近更新 更多