Mail attachment filename lost

0 votes
asked Feb 11, 2014 by John H (160 points)
edited Feb 12, 2014

Hi,

I have the follwing situation:

  1. I add attachment (RFC822) to a MailMessage.
  2. The MailMessage is converted to a MimeMessage
  3. The MimeMessage is utimately saved into a byte array.
  4. At some later point the MimeMessage is loaded from the byte array, converted to a MailMessage and the attachment retrieved from the MailMessage.

Upon retrieval of the attachment from MailMessage the filename is not equal to the original value (e.g. msg.eml). It is "ATT00001.eml", which appears to be autogenerated.

Does anyone know why this is happening and how I can avoid losing the original filename?

The following code snippet is used populate attachments for a Rebex.Mail.Message.

        foreach (Attachment a in message.Attachments)
        {
            mailMessage.Attachments.Add(new Rebex.Mail.Attachment(new MemoryStream (a.Content), 
                                                                                    a.FileName, 
                                                                                    a.MediaType));
        }

The following code snippet is used to retrieve attachments from Rebex.Mail.Message.

        foreach (Rebex.Mail.Attachment a in mailMessage.Attachments)
        {
            byte[] content = new byte[a.GetContentLength()];
            Stream cs = a.GetContentStream();
            cs.Read(content, 0, (int)cs.Length);
            cs.Close();
            attachments.Add(new Attachment(content, a.FileName, a.MediaType) { Id = id++ });
        }
Applies to: Rebex Secure Mail

2 Answers

0 votes
answered Feb 12, 2014 by John H (160 points)
edited Feb 12, 2014

After a bit more unit testing I found the filename of the retrieved attachment to equal the SUBJECT of the original attached RFC822 message. However, its not clear to me why I'm seeing ATT00001.eml in the production code.

commented Feb 12, 2014 by Tomas Knopp (58,890 points)
edited Feb 12, 2014

Hello, thank you for the additional information. We are already working on the problem and we'll get back to you with an answer as soon as possible.

0 votes
answered Feb 12, 2014 by Tomas Knopp (58,890 points)
edited Feb 12, 2014

I have tried to reproduce the problem, but the following code is working just fine for me and the attached filename is correct, i.e. 'mime.eml'. Please give it a try:

        // add attachment
        var mailMessage = new MailMessage();
        mailMessage.Attachments.Add(new Attachment(@"c:\temp\mime.eml"));

        // convert to MimeMessage and save to a stream
        var mimeMessage = mailMessage.ToMimeMessage();
        var ms = new MemoryStream();
        mimeMessage.Save(ms);
        ms.Seek(0, SeekOrigin.Begin);

        // load to MimeMessage
        var mmLoad = new MimeMessage();
        mmLoad.Load(ms);

        // convert to MailMessage
        var mmConverted = (MailMessage)mmLoad;

        Console.WriteLine(mmConverted.Attachments[0].FileName);

If the above code works, could you please let me know what you are doing differently so that we can reproduce the issue you reported? Preferably send us a short code which would reproduce it. Thank you!

...