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

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

提前致谢。

4

2 回答 2

3

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,

于 2009-08-12T12:17:29.503 回答
1

您不妨考虑Outlook Redemption

于 2009-08-12T12:29:49.857 回答