Outlook VBA宏,用于将电子邮件副本保存在本地文件夹中 [英] Outlook VBA macro for saving emails copies in a local folder
问题描述
无论何时发送电子邮件,我都希望将该电子邮件的副本以及所有附件保存在本地文件夹中.
Whenever sending an email, I would like a copy of that email to be saved in the local folder, together with all attachments.
我认为使用Outlook中的自定义规则是不可能的,但是也许可以使用VBA脚本来完成?
I don't think this is possible with a custom rule in Outlook but perhaps it could be done with a VBA script?
我使用Outlook和MS Exchange.
I use Outlook and MS Exchange.
推荐答案
当然可以使用Application_ItemSend
事件过程调用自定义过程来完成,该过程将已发送的邮件保存到本地文件夹中.
Sure it can be done using the Application_ItemSend
event procedure to call a custom procedure which will save your sent mails to a local folder.
此代码在"ThisOutlookSession"模块中.
This code goes in "ThisOutlookSession" module.
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Call SaveACopy(Item)
End Sub
Sub SaveACopy(Item As Object)
Const olMsg As Long = 3
Dim m As MailItem
Dim savePath As String
If TypeName(Item) <> "MailItem" Then Exit Sub
Set m = Item
savePath = "c:\users\your_user_name\desktop\" '## Modify as needed
savePath = savePath & m.Subject & Format(Now(), "yyyy-mm-dd-hhNNss")
savePath = savePath & ".msg"
m.SaveAs savePath, olMsg
End Sub
您将需要确保指定的路径是唯一的,等等,上面的示例是相当粗糙的.您还需要删除文件名中不能放入的任何非法字符(斜杠,管道等)...
You will need to ensure that the specified path is unique/etc., the above example is fairly crude. You also need strip out any illegal characters that can't be put in a file name (slash, pipes, etc.)...
作为一种选择,我建议您简单地定期存档您的文件夹.您可以将Outlook配置为将已发送邮件的副本保存到已发送"文件夹中,然后应该能够将该文件夹存档;单独保存每个项目似乎不尽人意.
As an alternative, I would suggest simply archiving your folder(s) periodically. You can configure Outlook to save a copy of sent mail to a "Sent" folder, and then you should be able to archive that folder; saving each item individually seems less-than-optimal.
这篇关于Outlook VBA宏,用于将电子邮件副本保存在本地文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!