Evaluating Aspose.Email

Hi,


In addition to my previous post re searching imap by unique ID, hoping you can help me with the following differences I have identified with my current implementation and what the alternatives are for a migration to Aspose:

  1. Removal of digital signature files - combination of IsSigned and RemoveSignature
  2. DateCreated vs DateReceived - there only appears to be a single Date within MailMessage
  3. Determine if an attachment is an embedded message and a method to return the MailMessage
  4. Determine if an attachment is TNEF and a method to return a list of attachments extracted from the container
  5. Determine if an attachment is a zip archive and a method to get the bytes or a stream to the attachment
  6. Determine if an attachment is inline - ContentDisposition.IsInline
  7. How to property determine the attachment filename, Attachment.Name or Attachment.ContentDisposition.FileName
  8. How to forward a MailMessage as an attachment to another MailMessage?

Thanks in advance, your assistance will help greatly in determining the suitability of Aspose.Email.

Regards
Trent

Hi Trent,

I hope the information that I shared earlier, regarding searching by Unique Id using IMAP, would be helpful for your requirements. For your queries posted in this thread, I would answer these one by one as follow. Please let us know if we can be of any additional help to you.

  1. The IsSigned method can be used to determine if it is a signed message, and the RemoveSignature() method can be used to decode the message then if it is signed.

  2. MailMessage.Date represents the date when the sender wrote the email.

When the message is received by POP/IMAP server, it adds information in “Received” header like IP address and received date. The following example illustrates how to get these two dates.

MailMessage msg = MailMessage.Load("test.eml", MessageFormat.Eml);

Console.WriteLine("Sent date: " + msg.Date);
Console.WriteLine("Received datetime from Headers: " + msg.Headers.Get(“Received”));
  1. You can extract embedded MSG attachments as follow from an email message:
static void ExtractAttachments()
{
MapiMessage msg = MapiMessage.FromFile("TestMsgInMsg.msg"); // This is the main message
foreach (MapiAttachment attachment in msg.Attachments)
{
if (attachment.ObjectData != null && attachment.ObjectData.IsOutlookMessage)
{
// For nested email attachments - save as msg
MapiMessage msgMessage = MapiMessage.FromStream((new MemoryStream(attachment.ObjectData.Data)));

// Interpret and save the message as MailMessage
MailMessageInterpretor mi = MailMessageInterpretorFactory .Instance.GetIntepretor(mapiMsg.MessageClass); MailMessage mailMsg = mi.Interpret(msgMessage); mailMsg.Save(Guid.NewGuid() + ".eml"), MailMessageSaveType.EmlFormat);

}
else
{
// For other attachments
attachment.Save(attachment.LongFileName);
}
}
}
  1. Aspose.Email extracts the attachments from TNEF and these are accessible to the user in the AttachmentCollection, as follow:
MailMessage mail = MailMessage.Load("Sample.eml");

foreach (Attachment att in mail.Attachments) { //Manage the attachments according to your needs }

In order to extract the messages from the winmail.dat, the TNEF container must first be loaded in MailMessage and then get access to its attachments, as follow:

MailMessage eml = MailMessage.Load("multi_attachments_in_tnef.eml", FileCompatibilityMode.PreserveTnefAttachments);
MailMessage winmail = MailMessage.LoadFromTnef(eml.Attachments[0].ContentStream);
foreach (Attachment att in winmail.Attachments) { Console.WriteLine(att.Name); }
  1. I am afraid to inform there is no well defined method to determine the attachment as a zip archive. You can always save attachment to MemoryStream using the Attachment.Save() method.

  2. There are a number of scenarios which affect the decision of considering an attachment as inline. Please refer to our online article Differentiating between Inline and Regular Attachments to get further insite into these details.

  3. Using MailMessage, Attachment.Name refers to the attachment file name and can be used to get the file name of the attachment.

  4. Please refer to the following code for your requirements. It loads an EML file in MailMessage, and then attaches this MailMessage to another MailMessage for sending purpose.

//Load an EML and save it to MemoryStream
MailMessage msg = MailMessage.Load("multi_attachments_in_tnef.eml");
MemoryStream ms = new MemoryStream();
msg.Save(ms);
//Initialize a new MailMesssage
MailMessage msg2 = new MailMessage("kashifiqb@gmail.com", "email@domain.com", "Test Subject", "Test Body");

//Prepare a new Attachment from the MemoryStream
Attachment att = new Attachment(ms, "message/rfc822");
//Assign a name
att.Name = "test.eml";
//Add the attachment
msg2.Attachments.Add(att);
//Save the message (msg2) or send it

Hi Kashif,


Thanks for the reponses, these are very thorough and should help me immensely. A couple of follow ups if you don’t mind:

3. I am using the ImapClient which provide me a MailMessage and not a MapiMessage. Is there any way I can determine if an attachment is an embedded message with MailMessage or would I need to save the MailMessage to a memory stream and load it into a MapiMessage object?

4. Just to confirm, if I don’t specify FileCompatibilityMode.PreserveTnefAttachments, Aspose.Email will take care of this extraction for me meaning I do not need to worry about this?

5. No problem

6. I assume MailMessage has this logic built in since it is separating these into the LinkedResourceCollection?

7. Will Attachment.Name always be a compliant filename or should this be sanitized before being saved to disk?

Thanks for you assistance.

Trent

Hi Trent,


You are always welcome to ask any query that is not clear or needs more clarification. We’ll try our best to assist you further.

3. Using MailMessage, the attachment’s “media type” can be used the identify the MSG attachment. Media type contains string value “message/rfc822” for the MSG type attachments. i.e.

if (att.ContentType.MediaType.Equals(“message/rfc822”)) //then its a MSG attachment

In addition, I would like to share with you that MapiMessage class provides the method FromMailMessage(MailMessage) that you can use instead of saving the MailMessage to stream and then reloading it using MapiMessage.

4. Setting the FileCompatibilityMode.PreserveTnefAttachments flag means that the TNEF attachments shouldn’t be decoded if present. If this flag isn’t set, Aspose.Email automatically decodes the attachments from the TNEF attachments.

6. You are right. In case you are using MailMessage, the LinkedResourceCollection gives you all the inline attachments.

7. Attachment.Name gives the attachment name that is displayed in the outlook and can be used as per your needs.

Please feel free to contact us in case you need further assistance. We will be glad to assist you further.