我想将电子邮件保存在本地文件夹中,并且看到了此链接 https://www.mrexcel.com/forum/excel-questions/361751-vba-saving-email-only-after-send-pushed.html 它基本上是使用class模块将电子邮件发送出去后保存的。 但是问题是,保存的电子邮件是预览电子邮件(在发送电子邮件之前显示的电子邮件),而不是已发送的电子邮件(您无法再对其进行任何编辑的电子邮件)
Dim cls_OL As New clsOutlook
Public objMail_SentMsg As Object
Public Emailpath As String
Sub SendEmail()
Dim OutMail As Object
Set cls_OL.obj_OL = CreateObject("Outlook.Application")
cls_OL.obj_OL.Session.Logon
Set OutMail = cls_OL.obj_OL.CreateItem(0)
Set objMail_SentMsg = OutMail
Emailpath = "V:\test\emailname.msg"
With OutMail
On Error Resume Next
'Assume this all strings variables are fine
.HTMLBody = strmsgContent1 & strmsgContent2
.to = ToEmail
.CC = CC
.BCC = BCC
.Subject = Subject
.Display
End With
Set OutMail = Nothing
End Sub
Option Explicit
Public WithEvents obj_OL As Outlook.Application
Private Sub obj_OL_ItemSend(ByVal Item As Object, Cancel As Boolean)
objMail_SentMsg.SaveAs Emailpath
Set obj_OL = Nothing
End Sub
它成功保存了电子邮件,但如上所述,仅保存了预览/显示电子邮件,而不是已发送的电子邮件。
非常感谢您的帮助。
答案 0 :(得分:1)
使用ItemAdd监视SentItems文件夹,而不是ItemSend。
请勿保存objMail_SentMsg,请保存由ItemAdd标识为添加到文件夹中的项目。
如果有必要区分不保存的邮件,请在创建邮件时在邮件中设置一些独特的特征。