首页 > 解决方案 > Outlook VBscript 方法 .Send 停止脚本

问题描述

我正在开发一个脚本来根据某些输入发送电子邮件,我能够制作电子邮件但不能使用该.Send方法发送它。

我收到以下错误:(请注意,该行.Send与原始案例中的使用相匹配)

在此处输入图像描述

我已经使用该.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. 任何想法?

标签: vbscriptoutlookautomationanywhere

解决方案


错误是E_ABORT。为什么显示消息立即调用发送?您要么显示消息(显示,但不发送),要么只发送消息而不显示(发送,但不显示)。


推荐阅读