【发布时间】:2015-05-08 00:38:11
【问题描述】:
- 我想在收到新邮件时删除附件.....
- 所以我使用 NewmailEx 事件.....也尝试了 Newmail 事件.....
- 我打开 Outlook --> 向我的 Outlook 邮件发送邮件 --> 事件被触发 --> 但收到的邮件未显示在我的未读邮件中,即 c# 编码没有收到收到的邮件 (这只发生在第一封邮件..关闭和打开 Outlook 之后..从第二封邮件开始,操作正常)
我在下面附上我的代码
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.NewMail += new Microsoft.Office.Interop.Outlook
.ApplicationEvents_11_NewMailEventHandler(ThisApplication_NewMail);
}
private void ThisApplication_NewMail()
{
Outlook.MAPIFolder inBox = this.Application.ActiveExplorer()
.Session.GetDefaultFolder(Outlook
.OlDefaultFolders.olFolderInbox);
Outlook.Items inBoxItems = inBox.Items;
Outlook.MailItem newEmail = null;
inBoxItems = inBoxItems.Restrict("[Unread] = true");
foreach (object collectionItem in inBoxItems)
{
newEmail = collectionItem as Outlook.MailItem;
if (newEmail != null)
{
if (newEmail.Attachments.Count > 0)
{
for (int i = 1; i <= newEmail
.Attachments.Count; i++)
{
newEmail.Attachments[1].Delete();
}
}
}
}
}
请帮助我阅读第一封邮件.....当 Outlook 打开时...
【问题讨论】: