none
Outlook 2010 PIA and Exchange Online: Email attachments are wrapped into a mail object attachment RRS feed

  • Question

  • Hi,

    we have an issue using PIAs from our .net application to send emails through Outlook 2010 (other versions not tested yet) in conjunction with Exchange Online. Our application creates a MailItem object and attaches a PDF document to it. The mail is then sent to a fax gateway which processes the PDF and sends it to a fax machine.

    This did work quite well until one of our clients migrated to Exchange Online. The email is still created and sent, but it seems like Outlook wraps the PDF into a mail attachment. So we then have an email with an email as attachment which in turn has the PDF document as attachment - at least that's what I am getting when I send the mail to an email recipient. Unfortunately, the fax gateway does not scan recursively through the mail attachment, and so the fax does not get sent.

    Interestingly, this only happens when the MailItem is not displayed on screen. Once you call Display() on it before sending, everything works fine.

    Has anyone experienced this, or an idea how to resolve this issue without displaying the MailItem first?

    Thanks,

    Kind Regards,

    Roland

    Thursday, June 23, 2016 2:46 PM

All replies

  • Are messages sent and received in Outlook? Please show your code.

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

    Thursday, June 23, 2016 5:09 PM
  • Hello,

    Do you have any add-ins installed for Outlook? What code do you use for the ItemSend event handler?


    [custom.development]

    Thursday, June 23, 2016 7:29 PM
  • Hi Dmitry,

    yes, the messages are sent and received in Outlook.

    Here's the code:

    Microsoft.Office.Interop.Outlook.Application outlook = new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook._MailItem mail = (Microsoft.Office.Interop.Outlook._MailItem)outlook.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem); mail.To = FaxNr; mail.Attachments.Add(m_FileInfo.FullName, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, 1, null);
    mail.Subject="some subject";
    // display the mail item, as otherwise, faxing does not work properly with fax gateway, Outlook 2012 and Exchange online mail.Display();
    mail.Send(); mail = null; outlook = null;


    Thanks for your help!

    Roland

    Friday, June 24, 2016 3:22 PM
  • Hi Eugene,

    I have found six active add-ins:

    1. Business Connectivity Services Add-In
    2. Microsoft Exchange Add-in
    3. Microsoft Outlook Social Connector
    4. Microsoft SharePoint Server Colleague Import Add-In
    5. Microsoft SharePoint Workspace Proxy for Outlook Add-In
    6. OneNote Notes about Outlook Items

    They all seem to be Microsoft Add-Ins.
    I have not subscribed to the ItemSend event handler, the code in my reply to Dmitrys post is actually all there is :)

    Thank you for your help,

    Roland

    Friday, June 24, 2016 3:26 PM
  • Hello Roland,

    The code looks good. Any Outlook add-ins may cause the issue. Do you have any installed for Outlook?

    Also I have noticed that you don't release underlying COM objects in the code instantly. All Outlook add-ins and automation applications should systematically release their references to Outlook objects when they are no longer needed. Failing to systematically release reference to Outlook objects can prevent Microsoft Office Outlook from shutting down properly.

    Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. Read more about that in the Systematically Releasing Objects article.  


    [custom.development]

    Friday, June 24, 2016 3:28 PM
  • Why would you call Display (modelessly) and then immediately Send? Pick one or another, but not both.

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

    Saturday, June 25, 2016 6:23 PM
  • Dmitry,

    A comment for the Display method explains why it is there:

    // display the mail item, as otherwise, faxing does not work properly with fax gateway, Outlook 2012 and Exchange online

    mail.Display();


    [custom.development]


    Sunday, June 26, 2016 7:30 PM
  • Hello Roland,

    Try to disable all of them. Does it work correctly then?


    [custom.development]

    Sunday, June 26, 2016 7:31 PM
  • That still does not make it a good idea. If the message does not get sent without Display, one would need to compare the recipients to check if the address type is set correctly. Is it "FAX"?

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

    Sunday, June 26, 2016 8:02 PM