我正在努力实现:
电子邮件已发送至Outlook"已发送邮件"因此电子邮件是 不在"发件箱"夹。
由于发送失败,电子邮件未返回(电子邮件将在 "收件箱"文件夹由postmaster@mail.hotmail.com提供)
以下代码用于通过Outlook从Access表单发送电子邮件:
GreetingController
非常感谢
诺贝特
答案 0 :(得分:0)
这两个都是异步的,您将能够在稍后,几秒甚至几分钟后处理通知。
我认为#1不会对您有所帮助 - 它只会告诉您网络没有断开连接。为什么这有关系?即使它已关闭,Outlook也会稍后发送消息。
对于#2,一切都取决于谁发送了NDR。如果是Exchange,您将能够找出错误的收件人地址。否则你可能只是得到一条消息,没有好办法弄清楚有问题的收件人是什么。
修改即可。对于Items.ItemAdd,请参阅以下内容(在我的脑海中):
Dim OutApp As Outlook.Application
Dim WithEvents SentItems As Outlook.Items
sub SentItems_ItemAdd(Item As Object)
MsgBox Item.Subject
end sub
Private Sub cmdEmail1_Click()
Dim OutMail As Outlook.MailItem
Dim strBody As String
Dim strPDF As String
Dim strFolder As String
Dim ns As Outlook.Namespacee
if (OutApp Is Nothing) Then
Set OutApp = CreateObject("Outlook.Application")
set ns = OutApp.GetNamespace("MAPI")
ns.Logon
set SentItems = ns.GetDefaultFolder(olFolderSentMail).Items
End If
Set OutMail = OutApp.CreateItem(olMailItem)
strBody = Me.txtSubject
strPDF = Me.txtFile
On Error Resume Next
With OutMail
.To = Me.txtemail
.CC = ""
.BCC = Me.txtBBCemail
.Subject = Me.txtSubject
.Body = Me.txtMessage
.Recipients.ResolveAll
' .SendUsingAccount = OutApp.Session.Accounts.Item(2) '2nd email
.SentOnBehalfOfName = Me.txtFromEmail
.Attachments.Add strPDF 'attachments
.Send
End With
Me.txtSent = "email was sent to Outlook "
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub