新Outlook.ItemEvents_10_ReplyEventHandler(MailItem_Reply) - 没有发件人的电子邮件信息
问题描述:
试图回复电子邮件新Outlook.ItemEvents_10_ReplyEventHandler(MailItem_Reply) - 没有发件人的电子邮件信息
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
currentExplorer = this.Application.ActiveExplorer();
currentExplorer.SelectionChange += new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(CurrentExplorer_Event);
}
private void CurrentExplorer_Event()
{
if (this.Application.ActiveExplorer().Selection.Count == 1
&& this.Application.ActiveExplorer().Selection[1] is Outlook.MailItem)
{
if (mailItem != null)
{
((Outlook.ItemEvents_10_Event)mailItem).Reply -= new Outlook.ItemEvents_10_ReplyEventHandler(MailItem_Reply);
}
mailItem = this.Application.ActiveExplorer().Selection[1];
((Outlook.ItemEvents_10_Event)mailItem).Reply += new
Outlook.ItemEvents_10_ReplyEventHandler(MailItem_Reply);
}
}
void MailItem_Reply(Object response, ref bool cancel)
{
Outlook.MailItem mailItem = (Outlook.MailItem)response;
mailItem.GetInspector.Activate();
string u = mailItem.Subject;
string x = mailItem.Sender.Name;
string r = mailItem.SenderName;
mailItem.Body = "Hi " + x.Split(' ')[0]+ "\n" + mailItem .Body;
}
当我得到null
为sender.name
和SenderName
我也得到之间
歧义方法'Microsoft.Office.Interop.Outlook._Inspector.Activate()'和非方法'Microsoft.Office.Interop.Outlook.InspectorEvents_10_Event.Activate'。使用方法组。
有人能告诉我如何正确地做到这一点,所以我可以自动回复,例如,发件人的名称,也消除了这种歧义?
答
(根据我们的讨论,因为这似乎起了作用)
的MailItem准备一个新的电子邮件时,通常不会初始化...
我通常做mail.Save();得到的属性初始化
对于偏色问题...
只投给 ((Microsoft.Office.Interop.Outlook._Inspector)mailItem.GetInspector).Activate(); - 它在不同界面中具有相同名称的事件。
MailItem在准备新电子邮件时通常不会被初始化 - 我通常使用mail.Save();'来获取属性的初始化。不确定是否存在歧义 - 您已经投了答复。 – NSGaga 2013-03-25 22:00:32
只需投射到'((Microsoft.Office.Interop.Outlook._Inspector)mailItem.GetInspector).Activate();' - 它在不同界面中具有相同名称下的事件。让我知道它是如何工作的(用@ ...) – NSGaga 2013-03-25 22:03:48
嘿,它有帮助吗?如果有,请让我知道发布答案,以便您可以关闭/答复 - 您应该始终这样做。 – NSGaga 2013-03-26 15:59:14