我嘗試從Outlook取消發送郵件。我需要從mailItem中獲取所有字段並關閉它,而無需發送。如何取消從Outlook發送郵件並關閉表單
在我的代碼我得到一個錯誤 - 無法在事件Item.Send執行命令Item.Close。
public partial class MyMainForm
{
Outlook.Application oApp;
Outlook.MailItem mailItem;
Timer timer_CloseMail;
private void Mail_in_outlook()
{
oApp = new Outlook.Application();
mailItem = Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
timer_CloseMail = new Timer();
timer_CloseMail.Interval = 1000;
timer_CloseMail.Tick += timer_CloseMail_Tick;
mailItem.To = "";
mailItem.Subject = "";
mailItem.HTMLBody = "";
oApp.ItemSend += oApp_ItemSend;
mailItem.DeleteAfterSubmit = true;
mailItem.Display(true);
// get mailItem.HTMLBody and other field....
}
void oApp_ItemSend(object Item,ref bool Cancel)
{
Cancel = true;
timer_CloseMail.Enabled = true;
}
private void timer_CloseMail_Tick(object sender, EventArgs e)
{
mailItem.Close(Outlook.OlInspectorClose.olDiscard);
timer_CloseMail.Enabled = false;
}
@ user3666197,不要[粗體單詞](http://stackoverflow.com/review/suggested-edits/5699992)。 – gunr2171 2014-09-04 20:53:43