none
MailItem.Sender causes outlook to suddenly crash RRS feed

  • Question

  • I tried to seek help with this problem many times but alas it proved to be too difficult for anyone to find solution over the internet.

    I managed to find even more details about it, so could anyone please have a look at it and tell me what to do?

    Should I:

     - file VSTO or office bug?

     - use some kind of workaround?

     - tell client to install some patch/fix/etc?

     - Change my job? ;)


    So the function that is causing problems is taken straight from msdn documentation - http://msdn.microsoft.com/en-us/library/office/ff184624%28v=office.15%29.aspx


    I added a lot of logging to that GetSenderSMTPAddress function, and sent updated addin to client (despite my efforts, I cannot reproduce that crash on my computer).


    Exact code I am using:

    private string GetSenderSMTPAddress(MailItem mail)
    {
        try
        {
            ApplicationLog.Instance.Log();
     
            const string prSmtpAddress = @"http://schemas.microsoft.com/mapi/proptag/0x39FE001E";
     
            if (mail == null)
            {
                throw new ArgumentNullException();
            }
     
            if (mail.SenderEmailType == null)
            {
                ApplicationLog.Instance.Log("Sprawdzany mail nie ma nadawcy");
                return "";
            }
     
            if (mail.SenderEmailType.ToUpper() != "EX")
            {
                return mail.SenderEmailAddress;
            }
            ApplicationLog.Instance.Log("Mail.SenderEmailType sprawdzone");
     
            var sender = mail.Sender;
            ApplicationLog.Instance.Log("Mail.Sender pobrane");
            if (sender == null)
            {
                ApplicationLog.Instance.Log("mail.sender jest nullem");
                return "";
            }
     
            //Now we have an AddressEntry representing the Sender
            if (sender.AddressEntryUserType == OlAddressEntryUserType.olExchangeUserAddressEntry
                || sender.AddressEntryUserType == OlAddressEntryUserType.olExchangeRemoteUserAddressEntry)
            {
                //Use the ExchangeUser object PrimarySMTPAddress
                ApplicationLog.Instance.Log("Mail.AddressEntryUserType sprawdzone, mail jest typu Exchange");
     
                var exchUser = sender.GetExchangeUser();
                ApplicationLog.Instance.Log("GetExchangeUser udało się");
     
                return exchUser == null ? null : exchUser.PrimarySmtpAddress;
            }
            ApplicationLog.Instance.Log("Mail.AddressEntryUserType sprawdzone, mail jest typu SMTP");
     
            return sender.PropertyAccessor.GetProperty(prSmtpAddress) as string;
        }
        catch (System.Exception e)
        {
            ApplicationLog.Instance.Log("Podczas próby pobrania maila: {0}", e.ToString());
            return "";
        }
    }

    And the last two log messages before a crash are always something like (namespace is deceptive, client is using outlook 2007):

    2014-12-15 17:46:54 [1] RateAddin.Outlook2013.RateController.GetSenderSMTPAddress
    2014-12-15 17:46:54 [1] RateAddin.Outlook2013.RateController.GetSenderSMTPAddress Mail.SenderEmailType sprawdzone

    i.e. reading mail.Sender property is causing crash of whole office (typical windows XP "send report/don't send" window). I stress that this is not exception thrown (that I could catch), or just addin killed, whole office crashes at once.

    I don't really have a screen of that, but I copied one from internet:

    http://www.integraxor.com/blog.img/2010/03/send-or-dont-send.png

    Client configuration:

    Office outlook 2007 (12.0.6680.5000) SP3 MSO (12.0.6683.5000)
    Windows XP Proffesional v2002 SP3

    Interesting thing is, according to minidump, last function called is RaiseException, and exception code is 0xe0434352 (standard catch-all .net exception code). I'm not sure what to think about that.

    If anyone is still reading this post, i uploaded minidump of crashed office https://tailcall.net/office.dmp if anyone wants to debug it himself.

    So thats all I know, if anyone could help me I would be really thankful.


    • Edited by msm_ Tuesday, December 16, 2014 3:56 PM
    Tuesday, December 16, 2014 3:49 PM

Answers

  • This means the user is using an older version of Outlook that does nor expose the MailItem.Sender property (it was introduced in Outlook 2010) - the call goes past the v-table, and boom! You have a crash.

    Luckily Outlook 2007 also exposes the MailItem.PropertyAccessor, so you should be able to retrieve PR_SENT_REPRESENTING_ENTRYID property (DASL name http://schemas.microsoft.com/mapi/proptag/0x00410102) using PropertyAccessor.GetProperty, convert it from an array to a hex string using PropertyAccessor.BinaryToString, then use it to call Namespace.GetAddressEntryFromID.

    If you want to support older version of Outlook (2003 and older), you would need to find some other means of retrieving the sender information - Redemption should be able to do the job.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by msm_ Wednesday, December 17, 2014 2:09 PM
    Wednesday, December 17, 2014 1:36 PM

All replies

  • Does it always happen with the same item? What kind of message store is it?

    Can you install OutlookSpy and check if it can retrieve the sender? Select the message, click thee Item button on the OutlookSpy toolbar, select the Sender property, click Browse.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Tuesday, December 16, 2014 4:28 PM
  • As far as I know, it happens with every exchange message (SMTP mails are ok, because they cause function to return .SenderEmailAddress 2 lines higher).

    > Can you install OutlookSpy and check if it can retrieve the sender? Select the message, click thee Item button on the OutlookSpy toolbar, select the Sender property, click Browse.

    I forwarded that suggestion to client, hopefully I will know the answer by tommorow.

    Edit: By the way, this addin is working in other system/office configurations (for example Windows 7/Outlook 2007 or Windows7/Outlook 2010 and even Windows7/Outlook 2013).

    Edit: Is this possible, that this problem is related to http://stackoverflow.com/questions/235231/how-to-avoid-outlook-security-alert-when-reading-outlook-message-from-c-sharp-pr ?

    • Edited by msm_ Tuesday, December 16, 2014 4:59 PM
    Tuesday, December 16, 2014 4:48 PM
  • I've received response from client.

    `I couldn't find any field with name "Sender". I attach screens with Sender* properties for exchange and SMTP email.`

    So here are the screens he sent me (sorry, I can't embed them or even hyperlink them)

    https://tailcall.net/office/

    (urls to single images just in case - http://tailcall.net/office/1.png, http://tailcall.net/office/2.png, http://tailcall.net/office/3.png, http://tailcall.net/office/4.png, http://tailcall.net/office/5.png, http://tailcall.net/office/6.png, http://tailcall.net/office/7.png)

    Is that normal? What should I think about it?

    Wednesday, December 17, 2014 12:03 PM
  • This means the user is using an older version of Outlook that does nor expose the MailItem.Sender property (it was introduced in Outlook 2010) - the call goes past the v-table, and boom! You have a crash.

    Luckily Outlook 2007 also exposes the MailItem.PropertyAccessor, so you should be able to retrieve PR_SENT_REPRESENTING_ENTRYID property (DASL name http://schemas.microsoft.com/mapi/proptag/0x00410102) using PropertyAccessor.GetProperty, convert it from an array to a hex string using PropertyAccessor.BinaryToString, then use it to call Namespace.GetAddressEntryFromID.

    If you want to support older version of Outlook (2003 and older), you would need to find some other means of retrieving the sender information - Redemption should be able to do the job.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by msm_ Wednesday, December 17, 2014 2:09 PM
    Wednesday, December 17, 2014 1:36 PM
  • I'd love to use redemption, alas it is not decision :>


    I am (unfortunately) supporting Outlook 2003 (but fortunately, not even older versions), so I created GetSMTPAddress method, i. e. complicated mess of marshalled native calls, reimplemented COM interfaces, iteration over MAPI properties and Black Magic that i hacked together using some weird internet snippets and my brain.


    Would this code work in newer versions of outlook (Outlook 2007, Outlook 2010, Outlook 2013) or is this method not supported currently?

    I mean, can I just copy that (GetSMTPAddress) method to newer plugin versions and reasonably hope that is will work?

    Wednesday, December 17, 2014 2:07 PM