runtime error 287 when sending mail using vba in access 2003

倖福魔咒の 提交于 2020-01-16 15:18:15

问题


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.


回答1:


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,




回答2:


You may wish to consider Outlook Redemption.



来源:https://stackoverflow.com/questions/1265655/runtime-error-287-when-sending-mail-using-vba-in-access-2003

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!