我是通过OOM做到的。我使用发件人的电子邮件地址和电子邮件主题来查找邮件。代码如下。
private string SelectMail(string addressTag, string subject)
{
Outlook.Application app = new Outlook.Application();
Outlook.Explorer explorer = app.ActiveExplorer();
explorer.ClearSelection();
string senderEmail = Utils.Setting.Get(addressTag);
IEnumerable<Outlook.MailItem> selectedMails = from Outlook.MailItem mailItem in explorer.CurrentFolder.Items
where mailItem.SenderEmailAddress == senderEmail && mailItem.Subject == subject
select mailItem;
Outlook.MailItem mail = selectedMails.FirstOrDefault<Outlook.MailItem>();
explorer.AddToSelection(mail);
return mail.Subject;
}