.MSG File Metadata Extraction - Sender SMTP Email RRS feed

  • Question

  • Our organization is currently in the process of extracting a processing old .MSG files that have been stored by current and possibly former employees. As part of this process we are trying to extract the Sender SMTP email address from these old emails. However since most of these were/are internal users, the msg file has the Sender Address stored as an exchange address. We have tried the following to with no luck:


    var senderAddress = string.Empty;
    using (var msg = new Storage.Message(emailFilePath))
        senderAddress = msg.Sender.Email;


    var senderEmailAddress = this.SafeExtractEmailAddress(mail.Sender, mail.SenderEmailAddress);

    private string SafeExtractEmailAddress(AddressEntry addressEntry, string currentEmail)
        var userEmailAddress = string.Empty;
        if (addressEntry != null &&
            (addressEntry.AddressEntryUserType == OlAddressEntryUserType.olExchangeUserAddressEntry
                || addressEntry.AddressEntryUserType == OlAddressEntryUserType.olExchangeRemoteUserAddressEntry))
            userEmailAddress = addressEntry.GetExchangeUser()?.PrimarySmtpAddress;
        if (string.IsNullOrWhiteSpace(userEmailAddress))
            var recipient = this.outlookApplication.Session.CreateRecipient(currentEmail);
            var exchangeUser = recipient?.AddressEntry.GetExchangeUser();
            userEmailAddress = exchangeUser?.PrimarySmtpAddress ?? currentEmail;
        return userEmailAddress.ToLowerInvariant();


    public string ExtractSender(MapiMessage msg)
        if (msg == null)
            throw new ArgumentNullException(nameof(msg));
        var senderEmailAddress = msg.SenderEmailAddress;
        ExchangeService exchangeService = this.exchangeServiceFactory.BuildService();
        // Create the ResolveNamesType and set the unresolved entry.
        if (msg.SenderAddressType == "EX")
            var resolutionCollection = exchangeService.ResolveName(msg.SenderEmailAddress, ResolveNameSearchLocation.ContactsThenDirectory, true);
            var nameResolutions = resolutionCollection.ToList();
            if (nameResolutions.Count > 0)
                var nameResolution = nameResolutions.ElementAt(0);
                senderEmailAddress = nameResolution.Mailbox.Address;
        return senderEmailAddress;

    Please assist with any other option we can look at to extract this.



    Friday, November 16, 2018 6:26 PM

All replies

  • You can do an LDAP query for the address matching the legacyExchangeDN property and then get the proxyAddresses multivalued property, and find the one beginning with SMTP: (case-sensitive).

    Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
    Celebrating 20 years of providing Exchange peer support!

    Friday, November 16, 2018 8:44 PM