Free Support Forum -

Write a message into a mbox file


i work with visual studio 2008 and
i would like to write a message (mailMessage) into a MBox file
this is the code:
'create the MBox file
writerMB = New MboxStorageWriter(“c:\test\mboxfile”, False) PROBLEM
’load a msg file
msg = MailMessage.Load(FileEntry, MessageFormat.Msg)
’ Add this message to storage

the problem is that i obtain a compilation error : New MboxStorageWriter is not possible because the class has the Musthinerit flag !!!
why ? MboxrdStorageWriter class works well.

how can i use it ?

thanks for your help


Hi Marc,

Please accept our apology for delayed response.

We have analyzed the information provided by you and found that MboxStorageWriter is a base class whose object cannot be initiated however MboxrdStorageWriter is a derived class and can be used for this purpose. Please have a look at the following code which uses MboxrdStorageWriter for writing to Mbox.

Imports Aspose.Email.Formats.Mbox
Imports Aspose.Email.Mail
Imports System.IO
Imports Aspose.Email.Outlook.Pst
Module Module1
Sub Main()
End Sub

Sub writeMBox()
Dim writerMB As MboxrdStorageWriter = New MboxrdStorageWriter("mboxfile", False)
Dim mailMsg As MailMessage = MailMessage.Load("Mail.msg", MessageFormat.Msg)
End Sub
Sub readMBox()
Dim readerMB As MboxrdStorageReader = New MboxrdStorageReader("mboxfile", False)
Dim msg As MailMessage = New MailMessage
msg = readerMB.ReadNextMessage()
While Not (msg Is Nothing)
msg.Save("MailOut.msg", MailMessageSaveType.OutlookMessageFormat)
msg = readerMB.ReadNextMessage()
End While
End Sub
End Module

Please feel free to share your feedback and we will be glad to provide you assistance if required.