Extension lost for an email .msg attachment

Hi,

In my application I process email with multiple kind of attachments. All works fine, but when an email have .msg attachments, the extension of attachments files is lost.
I use this code:

Dim msg As Aspose.Email.Mail.MailMessage = Aspose.Email.Mail.MailMessage.Load(“FILE_PATH”)

For Each a As Aspose.Email.Mail.Attachment In msg.Attachments
Dim attachmentName As String = a.Name
Next

The attachmentName doesn’t contains the file extension, but only the file name.
I have attachment a sample email.
I’m using the last version on the Aspose.Email Library (6.2.0.0).

Can I use a workaround to bypass the problem?

Thanks.

Hi,

Thank you for contacting Aspose Support team.

In such case, you can detect the media type of such an attachment and decide if it is another nested message using the following sample code. Please try it at your end and let us know your feedback.

Sample Code:

MailMessage msg = MailMessage.Load(“688502\Email with MSG attachment.msg”);

if (msg.Attachments[0].ContentType.MediaType.Equals(“message/rfc822”))
{
Console.WriteLine(“attachment is another message”);
}

Hello,

the workaround works, but now I would like to know if this is considered a bug or a “feature”.
I think that the name of the original attachment should not altered by removing the extension, but if this is the normal behaviour of the library I must modify all my code that works with attachments. Instead if it’s a bug I could wait for the fix.

Thanks.

Sorry,

but I’ve discovered another problem. I’m testing your workaround in a sample application:

<span style=“font-size:10.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;mso-ansi-language:IT;mso-fareast-language:
IT;mso-bidi-language:AR-SA”>string originalName = msg.Attachments[0].Name;<span style=“font-size:10.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;mso-ansi-language:IT;mso-fareast-language:
IT;mso-bidi-language:AR-SA”>

if (msg.Attachments[0].ContentType.MediaType.Equals(“message/rfc822”))

{
originalName+= “.msg”;<span style=“font-size:10.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;mso-ansi-language:IT;mso-fareast-language:
IT;mso-bidi-language:AR-SA”>

}<span style=“font-size:12.0pt;font-family:“Times New Roman”,serif;
mso-fareast-font-family:“Times New Roman”;mso-ansi-language:IT;mso-fareast-language:
IT;mso-bidi-language:AR-SA”>
<span style=“font-size:10.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;mso-ansi-language:IT;mso-fareast-language:
IT;mso-bidi-language:AR-SA”>
Then my application save the attachments in the file system or in the database. If I try to open the .msg attachment, Oulook starts and give an error. I have seen that the .msg attachments saved from Aspose.Email.Mail.Attachment are not MSG, but are converted in .EML. If I rename the files in EML Outlook works.

Is this a normal behaviour? Why the library alter the original attachments in this way?
If I undestand, my only option is to convert back .EML to .MSG. Is there a way to get the contents of the original attachment?

Thanks.

Hi,

When you load a MSG/EML file in MailMessage, then all it’s nested MSG attachments are also converted to MailMessage/EML and that is why saving it as MSG will raise error when opened with MS Outlook. This is an expected behavior of the API.

In order to save the attachment as MSG file, please try the following code and let us know your feedback.

Sample Code:

MailMessage msg = MailMessage.Load(“688502\Email with MSG attachment.msg”);

if (msg.Attachments[0].ContentType.MediaType.Equals(“message/rfc822”))
{
Console.WriteLine(“attachment is another message”);

//Save attachment to stream
MemoryStream ms = new MemoryStream();
msg.Save(ms);

//load into MailMessage
MailMessage attMsg = MailMessage.Load(ms);

attMsg.Save(“attMsg.msg”, Aspose.Email.Mail.SaveOptions.DefaultMsgUnicode);
}