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

发布于 2024-07-30 08:57:08 字数 595 浏览 3 评论 0原文

我目前正在编写一个 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

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

提前致谢。

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:

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绝對不後悔。 2024-08-06 08:57:08

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

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

除了发送“无对象”之外,您还可以发送表格、查询、表单、报告或表单。 无法通过这种方式附加普通文件。

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

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

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

希望这可以帮助,

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

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.

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).

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.

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.

Hope this helps,

半葬歌 2024-08-06 08:57:08

您不妨考虑Outlook 兑换

You may wish to consider Outlook Redemption.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文