在 Access 2003 中使用 vba 发送邮件时出现运行时错误 287
我目前正在编写一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Access 中使用
DoCmd.SendObject
发送电子邮件。 示例:除了发送“无对象”之外,您还可以发送表格、查询、表单、报告或表单。 无法通过这种方式附加普通文件。
如果您自动化 Outlook 并尝试发送邮件,Outlook 会捕获该邮件。 根据 Outlook 的安全设置,它完全不允许通过自动化发送邮件,它会使用弹出窗口询问用户是否允许自动化,或者只是发送邮件(请小心后者)。
如果由于安全性完全禁止通过自动化发送邮件或由于用户在确认对话框中单击“否”而中止发送邮件,则会出现错误 287。
有两种方法可以解决此问题:禁用安全性(完全禁用或让用户确认发送邮件),或签署您的 mdb 文件并在 Outlook 中信任它。 后者相当复杂,但最安全。
希望这可以帮助,
In Access use
DoCmd.SendObject
to send an e-mail. Example: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,
您不妨考虑Outlook 兑换。
You may wish to consider Outlook Redemption.