Quantcast
Channel: Aspose.Email Product Family
Viewing all articles
Browse latest Browse all 1367

Attachment is missing the content-disposition header

$
0
0
Hello,

I'm using the latest Aspose.Email dll for .NET.
I have the following code sample:

[Code]
        private void TestMethod() 
        {
            string SAVE_AS_FILE_LOCATION = @"C:\temp\test.eml";
            using (MailMessage message = new MailMessage())
            {
                message.IsDraft = false;
                message.Subject = "Test";
                message.Body = "This is a test body";
                message.From = new MailAddress("from@email.address");
                message.To.Add(new MailAddress("to@email.adress"));

                string attachmentMessage = @"<html><body>test</body></html>";
                MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(attachmentMessage));
                Attachment attachment = new Attachment(ms, "test.html", "text/html");
                // Uncommenting the next line will cause the attachment to add the header "Content-Disposition" which will properly generate the EML file
                //ContentDisposition cd = attachment.ContentDisposition;
                //if (cd == null)
                //{
                //    // Just to reference the property. This is a dummy code
                //}
                message.Attachments.Add(attachment);
                using (MemoryStream saveAsMemoryStream = new MemoryStream())
                {
                    message.Save(saveAsMemoryStream, SaveOptions.DefaultEml);

                    using (FileStream fs = File.Create(SAVE_AS_FILE_LOCATION))
                    {
                        if (saveAsMemoryStream.CanSeek)
                        {
                            saveAsMemoryStream.Seek(0, SeekOrigin.Begin);
                        }
                        saveAsMemoryStream.CopyTo(fs);
                    }
                }
            }
        }
[/Code]
When I open the file on disk (C:\temp\test.eml), the message displays wrong (I'm using Outlook). It show the body as the attachment and the attachment as the body.

If I uncomment the line of code mentioned above, it will work fine.
If I don't reference the property "ContentDisposition" on the attachment object, it will not be added to the list of headers and the eml file generated will be displayed/interpreted wrong.

Is this a known bug?

Thanks!

Viewing all articles
Browse latest Browse all 1367

Latest Images

Trending Articles



Latest Images