問題描述
如何知道是否收到或發送了電子郵件? (How to know if an e‑mail was received or sent?)
我製作了一個 VBA 腳本來將選定的電子郵件保存到不同的文件夾中。
有沒有一種方法可以在沒有用戶輸入的情況下知道是否收到或發送了電子郵件?
參考解法
方法 1:
You can check out the Sender‑related properties of the email item. The MailItem.Sender property which returns or sets an AddressEntry object that corresponds to the user of the account from which the MailItem
is sent. Checking that property and comparing to the Accounts configured in Outlook you may conclude where the message comes from. The Accounts
collection object contains a set of Account
objects representing the accounts available for the current profile. The purpose of the Accounts
collection object and the Account
object is to allow the enumeration of Account
objects in a given profile, the identification of the type of an Account
, and the use of a specific Account
object to send mail.
方法 2:
The only more or less reliable way is to check if MailItem.ReceivedByXYZ
properties (such as ReceivedByEntryID
) are set. They seem to be only present on the received messages. But I have seen cases where it was present on the sent messages.
You can check first if the parent folder is Inbox or Sent Items by comparing the current folder's entry id with the entry id of a folder received from Store.GetDefaultFolder
using Namespace.CompareEntryIDs
. If that fails, check on a ReceivedByXYZ
property.
(by z0rd、Eugene Astafiev、Dmitry Streblechenko)