来自MailItem对象的SentOnBehalfOfName和帐户名称(Outlook共享插件)

时间:2013-05-07 05:43:03

标签: c# outlook-addin mailitem shared-addin

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

请你能帮助我吗? 我希望收到来自SentOnBehalfOfName和帐户名称的电子邮件已发送。

2 个答案:

答案 0 :(得分:1)

只有在实际发送邮件并将其移动到“已发送邮件”文件夹后,才会设置发件人相关属性。您可能希望在“已发送邮件”文件夹上使用Items.ItemAdd事件。

答案 1 :(得分:0)

这是我使用的代码

    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的想法