首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Outlook.MailItem -无法从Outlook.MailItem访问,抄送(&B)

Outlook.MailItem -无法从Outlook.MailItem访问,抄送(&B)
EN

Stack Overflow用户
提问于 2014-10-31 20:04:43
回答 2查看 2K关注 0票数 0

我正在尝试通过自定义“发送”按钮的Application_ItemSend事件来使用C#创建Outlook外接程序。

在发送电子邮件之前,我需要所有电子邮件的详细信息。

当我运行下面的代码@ my home时,我通过将一些个人电子邮件id放入它的工作中得到了适当的结果。

但是当我在office outlook机器上运行这个类似的代码时,我得到了名字。

由于默认情况下,outlook的检查名称代码处于启用状态,因此它将返回名字和姓氏。

我正在使用Outlook 2010 @这两个地方。Office outlook映射到office active directory。我的家庭前景没有映射。谁能提供一个通用的解决方案,将给我所有的电子邮件地址使用(收件人,抄送,密件抄送和发件人),无论active directory映射或没有。

代码语言:javascript
复制
private void ThisAddIn_Startup(object sender, System.EventArgs e)        { 
          Application.ItemSend += new           Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);  
}

void Application_ItemSend(object Item, ref bool Cancel)        {
Outlook.MailItem mail = Item as Outlook.MailItem;            
Outlook.Inspector inspector = Item as Outlook.Inspector;

System.Windows.Forms.MessageBox.Show(mail.CC);
System.Windows.Forms.MessageBox.Show(mail.BCC);

} 
EN

回答 2

Stack Overflow用户

发布于 2015-03-18 21:04:44

也许已经很晚了,但是有人可以检查这个代码(它对我来说很有效)

代码语言:javascript
复制
    private string[] GetCCBCCFromEmail(Outlook.MailItem email)
    {
        string[] ccBCC = new string[] { "", "" };//cc y bcc
        Outlook.Recipients recipients = email.Recipients;

        foreach (Outlook.Recipient item in recipients)
        {
            switch (item.Type)
            {

                case (int)Outlook.OlMailRecipientType.olCC:                        
                    ccBCC[0] += GetEmail(item.AddressEntry) + ";";
                    break;
                case (int)Outlook.OlMailRecipientType.olBCC:
                    ccBCC[1] += GetEmail(item.AddressEntry) + ";";
                    break;
            }
        }
        return ccBCC;
    }
    private string GetEmail(Outlook.AddressEntry address) 
    {
        string addressStr = "";

        if (address.AddressEntryUserType ==
                Outlook.OlAddressEntryUserType.
                olExchangeUserAddressEntry
                || address.AddressEntryUserType ==
                Outlook.OlAddressEntryUserType.
                olExchangeRemoteUserAddressEntry)
        {
            //Use the ExchangeUser object PrimarySMTPAddress
            Outlook.ExchangeUser exchUser =
                address.GetExchangeUser();
            if (exchUser != null)
            {
                addressStr = exchUser.PrimarySmtpAddress;
            }
        }
        //Get the address from externals
        if (address.AddressEntryUserType == Outlook.OlAddressEntryUserType.
            olSmtpAddressEntry)
        {
            addressStr = address.Address;
        }

        return addressStr;
    }

希望能有所帮助

票数 1
EN

Stack Overflow用户

发布于 2014-10-31 21:38:07

To/CC/BCC属性(对应于MAPI中的PR_DISPLAY_ to /CC/BCC )由存储提供程序在保存项目时更新(MailItem.Save)。您还可以使用MailItem.Recipeints集合访问所有收件人。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26674312

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档