我正在編寫一個Outlook加載項,用於跟蹤回覆或轉發的電子郵件數量。在開發PC上,我使用了outlook 2010,代碼工作正常,但在最終用戶的PC上安裝的Outlook 2007中失敗。錯誤消息「無法執行運行時綁定到空引用」。在發送電子郵件之前,我需要的只是從收件人的電子郵件地址和主題發送的郵箱。 這裏是我發送電子郵件作爲新電子郵件的代碼,您能否告知我們在Office 2010和2007之間使用的API有何區別?我應該用什麼來代替?使用C#從Outlook 2007發送電子郵件時,無法執行運行時綁定到空引用
private void Send_Click(object sender, RibbonControlEventArgs e)
{
try
{
string _sub, _from, _to;
var inspector = this.Context as Outlook.Inspector;
dynamic mail = inspector.CurrentItem;
_from = mail.SendUsingAccount.DisplayName.ToString();
_to = mail.To.ToString();
_sub = mail.Subject.ToString();
/*
some extra code to save to database before sending email
*/
mail.Send();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error occured in send command");
}
}
不幸的是,我使用的是VS2012,它只有Office 2010的模板。 –