我正在使用 VBA 脚本在 Outlook 2010 中开发自动回复功能,以便每当有人给我发送电子邮件时,都会有自动回复,回复中包括我当前未读电子邮件的数量以及最早电子邮件的日期和时间。
关于代码,这是我目前所拥有的:
Sub AutoResponse(objmsg As Outlook.MailItem)
Dim objReply As MailItem
Dim omsgItem As Outlook.MailItem
Dim inbox As MAPIFolder
Set inbox = Application.GetNamespace("MAPI"). _
GetDefaultFolder(olFolderInbox)
Set objReply = objmsg.Reply
objReply.Subject = "Re: " & objReply.Subject
objReply.HTMLBody = "Hello," _
& "<br>" _
& "<br>" _
& "<br>" _
& "Thank you for your email. This is to verify that I have received your email. I currently have " & inbox.UnReadItemCount & " unread emails and the oldest email is (Code goes here) in my inbox and will be reading emails in a first in first out fashion. If the matter is urgent and cannot wait please call me directly" _
& "<br>" _
& "<br>" _
& "Regards, Mike" _
& "<br>" _
objReply.Send
Set objReply = Nothing
End Sub
确切的措辞可能会有所不同,但你应该明白我的意思。
我对此非常陌生,在 .Net 中开发不同的应用程序时,我能够将来自 Google 的一些代码和以前的知识拼凑在一起。
任何帮助将不胜感激。
答案1
Const olFolderInbox = 6
Dim mapiNamespace As Outlook.NameSpace
Dim inboxFolder As Outlook.Folder
Dim unreadItems As Outlook.Items
Set mapiNamespace = Application.GetNamespace("MAPI")
Set inboxFolder = mapiNamespace.GetDefaultFolder(olFolderInbox)
Set unreadItems = inboxFolder.Items.Restrict("[Unread] = True")
unreadItems.Sort "[ReceivedTime]", False
上述代码仅过滤收件箱中的未读邮件,并按接收时间排序。如果这样做,您可以轻松访问最旧的邮件:
unreadItems.GetFirst().ReceivedTime