locked
save to msg format RRS feed

  • Question

  • Hello

    I save email to file as code below. It is in .eml format.

    Private Sub MyRoutingAgent_OnSubmittedMessage(ByVal source As SubmittedMessageEventSource, ByVal e As QueuedMessageEventArgs) Handles Me.OnSubmittedMessage


    SaveStreamToFile( e.MailItem.GetMimeReadStream(), "C:\streammail1.eml")

    End Sub

    Public Sub SaveStreamToFile(ByVal stream As Stream, ByVal filename As String)
                Using destination As Stream = File.Create(filename)
                    Write(stream, destination)
                End Using
            End Sub

            Public Sub Write(ByVal from As Stream, ByVal toStream As Stream)
                Dim a As Integer = from.ReadByte()
                While a <> -1
                    toStream.WriteByte(CByte(a))
                    a = from.ReadByte()
                End While
            End Sub

    I want to save to .msg format. How can I do it ?

    Someone can give me the code or link.

    Wednesday, July 31, 2013 3:45 PM

Answers

  • The MSG (or OLE compound file format http://support.microsoft.com/kb/171907) is an Office file format and is used only by Outlook so there is nothing on the Exchange server side that will let save in this format. First question is why you want to save it as a MSG file ?unless your are dealing with TNEF Stream there's not much point. If you are dealing with TNEF stream then you need to convert the TNEF Stream to a MAPI object which is not trivial and will require a lot of overhead you generally don't want in a Transport Agent for performance reasons. A better idea if you really need to do this is just journal the message you want as a MSG file to a Journal Mailbox and export it from there.

    Cheers
    Glen 

    • Marked as answer by Dang Hong Son Friday, August 2, 2013 7:26 PM
    Thursday, August 1, 2013 7:21 AM
  • Thank you for supporting me !

    I must save to msg file because my exists app only find the .msg file format. I try and it really not easy with me. 

    So I use MSG .net to try and it's ok.


    • Marked as answer by Dang Hong Son Friday, August 2, 2013 7:26 PM
    Friday, August 2, 2013 7:26 PM

All replies

  • The MSG (or OLE compound file format http://support.microsoft.com/kb/171907) is an Office file format and is used only by Outlook so there is nothing on the Exchange server side that will let save in this format. First question is why you want to save it as a MSG file ?unless your are dealing with TNEF Stream there's not much point. If you are dealing with TNEF stream then you need to convert the TNEF Stream to a MAPI object which is not trivial and will require a lot of overhead you generally don't want in a Transport Agent for performance reasons. A better idea if you really need to do this is just journal the message you want as a MSG file to a Journal Mailbox and export it from there.

    Cheers
    Glen 

    • Marked as answer by Dang Hong Son Friday, August 2, 2013 7:26 PM
    Thursday, August 1, 2013 7:21 AM
  • Thank you for supporting me !

    I must save to msg file because my exists app only find the .msg file format. I try and it really not easy with me. 

    So I use MSG .net to try and it's ok.


    • Marked as answer by Dang Hong Son Friday, August 2, 2013 7:26 PM
    Friday, August 2, 2013 7:26 PM