I am attempting to generate a MSG file from scratch, to generate a template email for the user, using the Aspose.Network library (version 4.7.0.3), and it is partially working - a MSG file is generated, and will open within Outlook, however a number of properties are modified when Outlook reads the generated MSG file back.
- The Priority of the Message is lost completely
- The Attachments are modified to be mapped as Inline within the opened attachment.
I have also tried using the NormalMessageMailMessageInterpretor class, but calling save using this class generates a MailException with the following message
"Recent Aspose.Network does not support saving to Msg format file."
The code being used for the generation of the email is as follows:
Aspose.Network.License newLicence = new Aspose.Network.License();
newLicence.SetLicense(@"<valid license here>");
// Create a Mail Message
Aspose.Network.Mail.MailMessage newMessage = new Aspose.Network.Mail.MailMessage();
newMessage.To.Add("to@sample.com");
newMessage.TextBody = "Sample Text";
newMessage.Subject = "Sample Subject";
// Set the priority
newMessage.Priority = Aspose.Network.Mail.MailPriority.High;
// Add an Attachment
Aspose.Network.Mail.Attachment attachmentToAdd = new Aspose.Network.Mail.Attachment(@".\testattachment.txt");
attachmentToAdd.ContentDisposition.Inline = false;
attachmentToAdd.ContentDisposition.DispositionType = System.Net.Mime.DispositionTypeNames.Attachment;
newMessage.AddAttachment(attachmentToAdd);
// Now save this message as a .MSG file
Aspose.Network.Outlook.MapiMessage mapiMessage = Aspose.Network.Outlook.MapiMessage.FromMailMessage(newMessage);
// Set the Unsent Flag
mapiMessage.SetMessageFlags(Aspose.Network.Outlook.MapiMessageFlags.MSGFLAG_UNSENT);
mapiMessage.SetStringPropertyValue(Aspose.Network.Outlook.MapiPropertyTag.PR_SENDER_EMAIL_ADDRESS, "");
mapiMessage.SetStringPropertyValue(Aspose.Network.Outlook.MapiPropertyTag.PR_SENDER_NAME, "");
// Generates a msg file without Priority or Attachment within the Inline
mapiMessage.Save("outputmessage.msg");
// Throws a Message Exception
Aspose.Network.Outlook.NormalMessageMailMessageInterpretor messageInterpreter = new Aspose.Network.Outlook.NormalMessageMailMessageInterpretor();
messageInterpreter.Save(mapiMessage, new FileStream(@".\outputmessage2.msg", FileMode.Create), Aspose.Network.Mail.MessageFormat.Msg);