【问题标题】:Outlook VBscript method .Send stops scriptsOutlook VBscript 方法 .Send 停止脚本
【发布时间】:2019-04-23 22:43:44
【问题描述】:

我正在开发一个脚本来根据某些输入发送电子邮件,我可以制作电子邮件但不能使用 .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 发送电子邮件。有什么想法吗?

【问题讨论】:

  • 注意:我还通过 NameSpace 添加了 Logon 方法以确保我已登录。没有改变任何事情......

标签: vbscript outlook automationanywhere


【解决方案1】:

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

【讨论】:

  • 这里的.Display 实际上只是用于视觉测试目的。但是即使我删除了.Display 并且只使用.Send 它也不起作用并且会发生同样的错误......
  • 显示的邮件是否与所有收件人和附件都正常?如果你点击发送,它会被发送吗?
  • 是的,如果我.SendKeys("^~"),它也会被发送
  • 也许快速精确:我在 Exchange 帐户上(刚刚发现这个)
  • 您的机器上有最新的 AV 应用程序吗?
猜你喜欢
  • 1970-01-01
  • 2023-04-01
  • 1970-01-01
  • 2018-06-02
  • 1970-01-01
  • 1970-01-01
  • 2011-09-06
  • 2011-09-24
  • 2011-04-01
相关资源
最近更新 更多