Free Support Forum - aspose.com

Msg attachment in msg saved without extension

Hello,

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?

Thank you!

@panosk

Can you please share the source file with us along with extracted attachment so that I may investigate and help you out.

τεστ.zip (84.2 KB)

here you are.

@panosk

There are some custom declarations in sample code that you have shared. Can you please share a workable sample reproducing the issue.

image.png (20.4 KB)

string inputFile, string attachmentPrefix, string outputFolder, List attachments, List attachmentsNames, List metadataNames, List metadataValues
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++;
            }

@panosk

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.