Outlook VBscript方法.Send停止脚本

时间:2019-04-23 13:26:40

标签: vbscript outlook automationanywhere

我正在开发一个脚本,根据某些输入来发送电子邮件,我可以编写电子邮件,但不能使用.Send方法发送电子邮件。

我收到以下错误消息:(请注意,该行与原始情况下的.Send匹配)

enter image description here

我已经使用.SendKeys(^~)方法成功发送了电子邮件,但我想使用Outlook对象来发送电子邮件,而不仅仅是发送快捷方式。

这是我当前的代码:

' Declare all variables that will be used later on
    Dim outobj, mailobj, emailto, cc, subject, body, attachement
    Dim strFileText 
    Dim objFileToRead   
    Dim splitEmailto 

' Set the outlook application object
    Set outobj = CreateObject("Outlook.Application")  

' set the namespace
    Set myNamespace = outobj.GetNameSpace("MAPI")
    msgbox myNamespace.Folders(2)

' Set the mail item object
    Set mailobj = outobj.CreateItem(olMailItem) 

' Set a shell
    Set WshShell = WScript.CreateObject("WScript.shell")

' Get all the argument and assign
    emailto = "name@domain.eu"
    cc = "name@domain.eu"
    subject = "Simple Email"
    body = "Some Text"
    attachement = "C:\Users\name\Desktop\fileName.xls"

' Craft the email object
    With mailobj

        .Display

        ' assign the tos
        .To = cstr(emailto)

        ' add CCs
        .CC = cstr(cc)

        ' attach the relevant files
        If attachement <> "" Then
            If instr(attachement, ";") Then
                splitAtt = split(attachement, ";")
                For Each att In splitAtt 
                    If att <> "" Then
                        .Attachments.add cstr(att)
                    End If
                Next
            Else
                .Attachments.add cstr(attachement)
            End If
        End If

        If Subject <> "" Then
            .Subject = Subject ' sets the subject   
        End If

        If body <> "" Then
            .Body = body ' sets the body
        End If

        .Send

    End With

' Clear the memory
    Set outobj = Nothing
    Set mailobj = Nothing

' check for no more events in the sending event

' Report out & Quits
    WScript.StdOut.WriteLine("Email sent")
    WScript.Quit

我希望能够使用.Send发送电子邮件。有什么主意吗?

1 个答案:

答案 0 :(得分:0)

错误为E_ABORT。 您为什么立即显示消息,立即致电Send?您可以显示消息(显示,但不发送),也可以将其发送出去同时显示(发送,但不显示)。