Search code examples
c#outlookoutlook-addinoutlook-redemption

How to add blocked file types as attachments in an outlook mail item?


I am trying to extract attachments from a mail and attach those files to another mail Item.

Everything works fine but if I try to add an attachment wich has a blocked extension, the attachment won't get added to the mail item. Following is what I have done:

private void addAttachments( Redemption.RDOMail sourceMail , ref Redemption.RDOMail targetMail )                
{
    foreach (Redemption.RDOAttachment attachment in sourceMail.Attachments)
    {
        // Saving attachment files from source mail on local disk 
        attachment.SaveAsFile(/*File Path*/);

        // adding attachment to target mail from saved location
        //At this point, target mail has the attachment count incremented
        targetMail.Attachments.Add(/*File PAth*/ + attachment.DisplayName);

        // deleting file, saved on local disk
        File.Delete(/*File Path + attachment.DisplayName*/);                   
    }

    targetMail.Save();

    // when the mail item is being displayed, the added attachment with the *.EXE,
    //or all the other attachment extentions which are blocked from viewing by outlook is gone.
    // This does not happen for other attachment files
    targetMail.Display();
}

Why these particular attachment types won't get displayed?


Solution

  • Why these particular attachment types won't get displayed?

    That is a Microsoft Office feature, not your software broken.

    According to Microsoft, there are three options:

    • Use a shared server
    • Use a file compression utility
    • Rename the file

    I had like to add a fourth:

    I would go for option 2, since that is the easiest to implement, and doesn't need to change the sender and receiver PC (which you can't always control and which might have security implications).