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



我正在使用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。

只有在消息实际发送并移动到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

相关内容

最新更新