在 access 2003 中使用 vba 发送邮件时出现运行时错误 287

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1265655/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 10:41:19  来源:igfitidea点击:

runtime error 287 when sending mail using vba in access 2003

vbaoutlook-2003

提问by Fionnuala

I am currently writing a vba macro to send e-mails and the messages are created but do not sent as an error is generated. My current code is:

我目前正在编写一个 vba 宏来发送电子邮件,并且创建了消息,但在生成错误时不发送。我目前的代码是:

Function CreateHURMail(Filename)

Dim olApp As Outlook.Application
Dim objMail As Outlook.MailItem
Set olApp = New Outlook.Application
Set objMail = olApp.CreateItem(olMailItem)

With objMail
    .Subject = "Test Message"
    .Body = "Body Text"
    .To = "abc@xyz"
    .Attachments.Add (Filename)
    .Display

    On Error Resume Next
    .Send

    'If Err.Number = 287 Then
    '    MsgBox "Still doesn't work!", vbOKOnly, "DOH!"
    'End If
End With


End Function

Does anyone know how to fix this?

有谁知道如何解决这一问题?

Thanks in advance.

提前致谢。

回答by Guillaume Hanique

In Access use DoCmd.SendObjectto send an e-mail. Example:

在 Access 中用于DoCmd.SendObject发送电子邮件。例子:

Call DoCmd.SendObject(acSendNoObject, To:="abc@xyz", 
    Subject:="Test Message", MessageText:="Body Text", EditMessage:=true)

In stead of sending No Object, you can also send tables, queries, forms, reports or forms. It isn't possible to attach a normal file, this way.

除了发送 No Object,您还可以发送表格、查询、表单、报表或表单。不可能以这种方式附加普通文件。

If you automate Outlook and try to send a message, it is caught by Outlook. Depending on Outlook's security setting, it disallows sending mail through automation completely, it asks the user using a popup if automation is allowed or it simply sends the mail (be careful with the latter).

如果您自动化 Outlook 并尝试发送消息,它会被 Outlook 捕获。根据 Outlook 的安全设置,它完全不允许通过自动化发送邮件,它会使用弹出窗口询问用户是否允许自动化,或者它只是发送邮件(小心后者)。

If sending the mail is aborted either because the security disallows sending mail via automation completely or because the user clicked "no" on the confirmation dialog box, error 287 occurs.

如果由于安全性完全禁止通过自动化发送邮件或因为用户在确认对话框中单击“否”而中止发送邮件,则会发生错误 287。

There are two ways to resolve it: disable security (completely or let the user confirm sending the mail), or sign your mdb-file and trust it in Outlook. The latter is rather complicated, but the most secure.

有两种解决方法:禁用安全性(完全或让用户确认发送邮件),或签署您的 mdb 文件并在 Outlook 中信任它。后者比较复杂,但最安全。

Hope this helps,

希望这可以帮助,

回答by Fionnuala

You may wish to consider Outlook Redemption.

您不妨考虑一下Outlook Redemption