从MailItem对象(Outlook共享插件)中获取From, SentOnBehalfOfName和Account

本文关键字:From 获取 SentOnBehalfOfName Account 对象 MailItem Outlook 插件 共享 | 更新日期: 2023-09-27 18:12:36

我正在使用Vs2010 ->可扩展性->共享插件我已经添加了一个事件处理程序到我的ItemSend

applicationObject.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(applicationObject_ItemSend);  
void applicationObject_ItemSend(object Item, ref bool Cancel)
{
    if(Item is Outlook.MailItem)
    {
        Outlook.MailItem mailItem = Item as Outlook.MailItem;
        if (mailItem != null)
        {
           MessageBox.Show("Sender's Email Address "+mailItem.SenderEmailAddress);
           MessageBox.Show("Sender's Email Address "+mailItem.SentOnBehalfOfName); 
          MessageBox.Show("Sender's Email Address "+mailItem.SendUsingAccount);
        }
    }
}

mailItem.SenderEmailAddress,mailItem.SentOnBehalfOfNamemailItem.SendUsingAccount我得到了所有这些属性null

谁能帮我一下吗我想从发送的邮件中获得From, SentOnBehalfOfName和Account name From。

从MailItem对象(Outlook共享插件)中获取From, SentOnBehalfOfName和Account

只有在消息实际发送并移动到sent Items文件夹后才能设置发件人相关属性。您可能需要使用Items。

这是我使用的代码

    public Outlook.MAPIFolder sentFolder = null;
    public Outlook.Items itmsSentFolder = null;
    sentFolder = applicationObject.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
    itmsSentFolder = sentFolder.Items;
    itmsSentFolder.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(itmsSentFolder_ItemAdd); 
void itmsSentFolder_ItemAdd(object Item)
        {
                if (Item is Outlook.MailItem)
                {
                    Outlook.MailItem mailItem = Item as Outlook.MailItem;
                    if (mailItem != null)
                    {
                        MessageBox.Show("Sender's Email Address " + mailItem.SenderEmailAddress);
                        MessageBox.Show("Sent On Behalf Of Name " + mailItem.SentOnBehalfOfName);
                        Outlook.Account ac = (Outlook.Account)mailItem.SendUsingAccount;
                        if(ac != null)
                        {
                            MessageBox.Show("Sender's Account Name " + ac.SmtpAddress);
                        }
                    }
            }
        }

谢谢你的想法Dmitry Streblechenko