none
Getting Error Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND)) RRS feed

  • Question

  • Hi,

    I am developing Outlook 2013 Addin.

    My scenario:

    1. Get email data of selected email from outlook mail window

    2. Create new email item 

    3. Update new email item with the email data from selected email

    4. send email

    If i am selecting email without attachments and do the operation , then it is working fine.

    But if selected email has attachments, then i am getting error Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))

    To get Selected email data, i am using below code

    MailItem mailItem = null;
    Attachments mtAttachments = null;
    
    Explorer explorer = Globals.ThisAddIn.Application.ActiveExplorer();
    
    if (explorer != null && explorer.Selection != null && explorer.Selection.Count > 0)
                    {
                        object item = explorer.Selection[1];
                        if (item is MailItem)
                        {
                            mailItem = item as MailItem;
                            subject = mailItem.Subject;
                            body = mailItem.HTMLBody;
                            mtAttachments = mailItem.Attachments;
                        }
                    }    

    To Send new email with attachments i am using below code.

    And i am getting below Error .

    Can any one please help me.?

    Tuesday, November 11, 2014 6:59 AM

Answers

  • Hi Eugene

    Thanks,

    I have updated my code as per below

                    MailItem mailItem = null;
                    Attachments mtAttachments = null;
    
                    Explorer explorer = Globals.ThisAddIn.Application.ActiveExplorer();
    
                    if (explorer != null && explorer.Selection != null && explorer.Selection.Count > 0)
                    {
                        object item = explorer.Selection[1];
                        if (item is MailItem)
                        {
                            mailItem = item as MailItem;
                            subject = mailItem.Subject;
                            body = mailItem.HTMLBody;
                            mtAttachments = mailItem.Attachments;
    
                            if (mailItem.Attachments.Count > 0)
                            {
                                for (int j = 1; j <= mailItem
                                   .Attachments.Count; j++)
                                {
                                    if (mailItem.Attachments[j].PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x7FFE000B") == false)
                                    {
                                        mailItem.Attachments[j].SaveAsFile
                                            (@"C:\TestFileSave\" +
                                            mailItem.Attachments[j].FileName);
                                    }
                                }
                            }
                        }
                    }

    and it is woring fine.

    Thanks for your help

    • Marked as answer by PB5590 Wednesday, November 12, 2014 5:29 AM
    Wednesday, November 12, 2014 5:29 AM

All replies

  • Hello Prashant,

    The Add method of the Attachments class does't accept an instance of the Attachment class. You need to specify the filepath instead.

    As I already said in another thread with your question, you have to save the attached file on a disk using the SaveAs method of the Attachment class. Then you can use the Add method of the Attachments class to attach a file (pointing to any file on a disk).

    Tuesday, November 11, 2014 7:31 AM
  • Hello Eugene,

    Thanks for your reply.

    You are right about saving attachments to disk.

    I have tried it, but now problem is, when i try to save attachments to disk, then it is also saving images from signatures, which is completely wrong.

    Tuesday, November 11, 2014 7:38 AM
  • Embedded images are stored in the item as hidden attachments and are referenced in the html markup of the body using the "cid" attribute.

    Try using any Extended MAPI viewer (MFCMAPI or OutlookSpy) for observing low level properties.


    The PR_ATTACHMENT_HIDDEN property "http://schemas.microsoft.com/mapi/proptag/0x7FFE000B".
    Tuesday, November 11, 2014 9:06 AM
  • Can you please tell me reference link to achieve above functionality.

    It will be really helpful.

    Thanks

    Wednesday, November 12, 2014 4:38 AM
  • Hi Eugene

    Thanks,

    I have updated my code as per below

                    MailItem mailItem = null;
                    Attachments mtAttachments = null;
    
                    Explorer explorer = Globals.ThisAddIn.Application.ActiveExplorer();
    
                    if (explorer != null && explorer.Selection != null && explorer.Selection.Count > 0)
                    {
                        object item = explorer.Selection[1];
                        if (item is MailItem)
                        {
                            mailItem = item as MailItem;
                            subject = mailItem.Subject;
                            body = mailItem.HTMLBody;
                            mtAttachments = mailItem.Attachments;
    
                            if (mailItem.Attachments.Count > 0)
                            {
                                for (int j = 1; j <= mailItem
                                   .Attachments.Count; j++)
                                {
                                    if (mailItem.Attachments[j].PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x7FFE000B") == false)
                                    {
                                        mailItem.Attachments[j].SaveAsFile
                                            (@"C:\TestFileSave\" +
                                            mailItem.Attachments[j].FileName);
                                    }
                                }
                            }
                        }
                    }

    and it is woring fine.

    Thanks for your help

    • Marked as answer by PB5590 Wednesday, November 12, 2014 5:29 AM
    Wednesday, November 12, 2014 5:29 AM