ArgumentNullException when saving MSG to EML

I’ve been using the following code to save .MSG’s to .EML’s when they are attached to other .MSG’s.



if(!Directory.Exists(“ATTACHMENT EMAILS”))

Directory.CreateDirectory(“ATTACHMENT EMAILS”);

string location = @“ATTACHMENT EMAILS/ATTACHED_MESSAGE” + getSHA1(att.Content.ToString()) + “.eml”;

Message.MapiMessage attMsg = Message.MapiMessage.FromProperties(att.ObjectData.Properties);

Message.MailMessageInterpretor mi = Message.MailMessageInterpretorFactory.Instance.GetIntepretor(attMsg.MessageClass);

using (FileStream fs = new FileStream(location, FileMode.Create))

{

try

{

mi.Save(attMsg, fs, Aspose.Network.Mail.MessageFormat.Eml);

}

catch (Exception ex)

{

throw ex;

}





I am currently getting an ArgumentNullException when trying to save it.



Any help is appreciated.

Here is a stack trace if it helps.

at Aspose.Network.Mime.x83903e31fd6d37d2.x20c291f0c9343969(String xb41faee6912a2313, String x9c1b9627c9a8cad5)
at Aspose.Network.Mail.AttachmentBase.x20c291f0c9343969(String xb41faee6912a2313, String x9c1b9627c9a8cad5)
at Aspose.Network.Mail.MailMessage.set_TextBody(String value)
at Aspose.Network.Outlook.MailMessageInterpretor.LoadMessageBodyText(MailMessage mailmessage, MapiMessage mapiMessage)
at Aspose.Network.Outlook.MailMessageInterpretor.LoadMessageBody(MailMessage mailmessage, MapiMessage mapiMessage)
at Aspose.Network.Outlook.MailMessageInterpretor.Interpret(MapiMessage mapiMessage)
at EDR.Form1.CheckAttachmentsForMSG(MapiMessage message, String Repo) in C:\Users\mjs2303\Documents\Visual Studio 2005\Projects\EDR\EDR\Form1.cs:line 352
at EDR.Form1.AddMessageToRepo(String Location, String Repo) in C:\Users\mjs2303\Documents\Visual Studio 2005\Projects\EDR\EDR\Form1.cs:line 188
at EDR.Form1.loadIntoRepositoryAToolStripMenuItem_Click(Object sender, EventArgs e) in C:\Users\mjs2303\Documents\Visual Studio 2005\Projects\EDR\EDR\Form1.cs:line 419
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at EDR.Program.Main() in C:\Users\mjs2303\Documents\Visual Studio 2005\Projects\EDR\EDR\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

Hello,

Could you please attach your eml files for our debugging?

Thanks

Hello,

We have confirmed this is a known issue on converting the embedded message file. Saving the embedded message file to disk is not yet supported. The development team is still working on this, we will fix it in the coming release.

A possible workaround for this:

1. Save the message to eml file

2. Get the embedded message file as eml format

3. Convert it to msg file format.

Sample code:

MailMessage msg = MailMessage.Load(@"file-name",MessageFormat.Msg);

msg.Attachments[0].Save(@"embedded.eml");

MailMessage embeddedEml = MailMessage.Load(@"embeded.eml", MessageFormat.Eml);

embeddedEml.Save(@"embedded.msg", MessageFormat.Msg);

Thanks