检查outlook发送电子邮件

时间:2016-05-24 18:36:13

标签: vbscript

我的第一个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"言。

1 个答案:

答案 0 :(得分:0)

If Process.Name = "outlook.exe" Then
    send
Else
    open    
End If

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