none
C# Outlook multiple attachments combine to 1 single RRS feed

  • Question

  • Hello,

    We have a mailbox where users send emails with attachments. The attachments can be any number. We have a requirement where lets say id a users send email with 5 attachments on type jpeg then we need to combine all 5 attachments into 1 and save it. How do i do it in C#?

    Any pointers will be appreciated!

    Thanks!

    Tuesday, June 27, 2017 8:10 PM

All replies

  • Hello Viral,

    You can handle the ItemSend event of the Application class which is fired whenever an Microsoft Outlook item is sent, either by the user through an  Inspector (before the inspector is closed, but after the user clicks the Send button) or when the Send method for an Outlook item. So, you can check out the Attachments collection of the item passed as an argument and cancel any further processing if required (see the Cancel parameter). For example, a VBA macro:

    Public WithEvents myOlApp As Outlook.Application 
    
    
    Public Sub Initialize_handler() 
     Set myOlApp = Outlook.Application 
    End Sub 
    
    Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel As Boolean) 
     Dim prompt As String 
     prompt = "Are you sure you want to send " &; Item.Subject &; "?" 
     If MsgBox(prompt, vbYesNo + vbQuestion, "Sample") = vbNo Then 
      Cancel = True 
     End If 
    End Sub

    we need to combine all 5 attachments into 1 and save it.

    The Attachments collection doesn't provide any methods for dealing with attachments on the fly. You need to save the attachment on the disk first (see the SaveAsFile method), do whatever you need with the file saved and then you can re-add it anew.  


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Tuesday, June 27, 2017 8:46 PM
  • Hi Viral,

    Could you share us more information about your issue?

    >> where lets say id a users send email with 5 attachments on type jpeg then we need to combine all 5 attachments into 1 and save it

    What do you mean combine into 1? Do you need to compress them into zip? When do you want to process compress? Do you want to process when use send the email or when you receive the email at your client side?

    >> How do i do it in C#?

    Which project do you want? Do you want winform project or Office VSTO solution? With Winform, you could achieve this with button, with VSTO, you could achieve this in Outlook VSTO solution.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 30, 2017 7:35 AM