i’m using this code block to read attachment names from an msg file.
Aspose.Email.MailMessage mailMsg = Aspose.Email.MailMessage.Load(inputFile);
int i = 1;
foreach (Aspose.Email.Attachment attachment in mailMsg.Attachments)
{
string attachmentFilename = "";
if (outputFolder.Length > 0)
{
if (outputFolder.EndsWith("\\"))
outputFolder.Remove(outputFolder.Length - 1);
attachmentFilename = Path.Combine(outputFolder, attachmentPrefix + i.ToString());
}
else
attachmentFilename = attachmentPrefix + i.ToString();
attachment.Save(attachmentFilename);
attachments.Add(attachmentFilename);
attachmentsNames.Add(attachment.Name);
i++;
When an attachment is type “.msg”, it is saved without the extension, creating a number of problems. Is this supposed to happen. Is there a way to track if an attachment is msg and maybe add the file extension?
I have created an issue with ID EMAILNET-39953 in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.
In attached project we have shown how to save inner message with appropriate extension.
Note - by default inner message converted in format of parent message. If you want preserve format of inner message to use PreserveEmbeddedMessageFormat option.
Hello support @mudassir.fayyaz
Is this issue been fixed on the latest release? I’m still having the issue where aspose is saving email attachments without extension (.eml file). Also, can you share the sample project with the workaround with me?
Thank you for the provided information. In your sample file the message contains an embedded message which may not have an extension property, as it is a message in eml format. In order to save an attachment with extension, you should make sure that the attachment is an embedded message and has extension. In case there is no extension, add it while saving. Use the following code:
// Loop through attachments
foreach (var attachment in msg.Attachments)
{
// Check if attachment is an embedded
if (attachment.IsEmbeddedMessage)
{
// Check if attachment has eml extension
var extension = Path.GetExtension(attachment.Name);
// Add .eml extension if it is absent
if (extension == "")
{
attachment.Name += ".eml";
}
}
attachment.Save(path + "\\" + timestamp + attachment.Name);
...
}
Yes, this is an expected behavior. Embedded messages may not have an extension, as their format is same to the parent message. This is the reason why Outlook doesn’t add extensions to embedded messages, as it can display an embedded message properly anyway.