Как получить адрес электронной почты отправителя, если пользователь является пользователем активного каталога?

Я использую get_SenderEmailAddress () объекта Outlook :: _ MailItem, чтобы получить адрес электронной почты отправителя. Но если пользователь является активным пользователем каталога, то recipientitem.address выглядит так: / o = organizationg / ou = административная группа обмена / cn = recipients / cn = xxxxxxxxxx.

Есть ли другой способ узнать адрес электронной почты отправителя?


person shyam    schedule 25.05.2017    source источник


Ответы (2)


Я использую это, чтобы получить почтовый адрес отправителя.

 private string GetSenderSMTPAddress(Outlook.MailItem mail)
    {
        try
        {
            string PR_SMTP_ADDRESS =
                    @"http://schemas.microsoft.com/mapi/proptag/0x39FE001E"; if (mail == null)
            {
                throw new ArgumentNullException();
            }
            if (mail.SenderEmailType == "EX")
            {
                Outlook.AddressEntry sender =
                    mail.Sender;
                if (sender != null)
                {
                    //Now we have an AddressEntry representing the Sender
                    if (sender.AddressEntryUserType ==
                        Outlook.OlAddressEntryUserType.
                        olExchangeUserAddressEntry
                        || sender.AddressEntryUserType ==
                        Outlook.OlAddressEntryUserType.
                        olExchangeRemoteUserAddressEntry)
                    {
                        //Use the ExchangeUser object PrimarySMTPAddress
                        Outlook.ExchangeUser exchUser =
                            sender.GetExchangeUser();
                        if (exchUser != null)
                        {
                            return exchUser.PrimarySmtpAddress;
                        }
                        else
                        {
                            return null;
                        }
                    }
                    else
                    {
                        return sender.PropertyAccessor.GetProperty(
                            PR_SMTP_ADDRESS) as string;
                    }
                }
                else
                {
                    return null;
                }
            }
            else
            {
                return mail.SenderEmailAddress;
            }
        }
        catch (Exception ex)
        {
            return null;
        }
    }
person Gokul    schedule 26.05.2017

Похоже, это совершенно действующий адрес электронной почты типа "EX" (в отличие от «SMTP»).

Если вам нужен SMTP-адрес, используйте MailItem.Sender.GetExchangeUser().PrimarySmtpAddress. Будьте готовы обрабатывать значения NULL и исключения. Но сначала проверьте свойство MailItems.SenderEmailType - если это "SMTP", вы все равно можете использовать SenderEmailAddress.

person Dmitry Streblechenko    schedule 25.05.2017