Hello,
I’m using the latest Aspose.Email dll for .NET.
I have the following code sample:
</div><div><div> private void TestMethod() </div><div> {</div><div> string SAVE_AS_FILE_LOCATION = @"C:\temp\test.eml";</div><div> using (MailMessage message = new MailMessage())</div><div> {</div><div> message.IsDraft = false;</div><div> message.Subject = "Test";</div><div> message.Body = "This is a test body";</div><div> message.From = new MailAddress("from@email.address");</div><div> message.To.Add(new MailAddress("to@email.adress"));</div><div><br></div><div> string attachmentMessage = @"<html><body>test</body></html>";</div><div> MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(attachmentMessage));</div><div> Attachment attachment = new Attachment(ms, "test.html", "text/html");</div><div> // Uncommenting the next line will cause the attachment to add the header "Content-Disposition" which will properly generate the EML file</div><div> //ContentDisposition cd = attachment.ContentDisposition;</div><div> //if (cd == null)</div><div> //{</div><div> // // Just to reference the property. This is a dummy code</div><div> //}</div><div> message.Attachments.Add(attachment);</div><div> using (MemoryStream saveAsMemoryStream = new MemoryStream())</div><div> {</div><div> message.Save(saveAsMemoryStream, SaveOptions.DefaultEml);</div><div><br></div><div> using (FileStream fs = File.Create(SAVE_AS_FILE_LOCATION))</div><div> {</div><div> if (saveAsMemoryStream.CanSeek)</div><div> {</div><div> saveAsMemoryStream.Seek(0, SeekOrigin.Begin);</div><div> }</div><div> saveAsMemoryStream.CopyTo(fs);</div><div> }</div><div> }</div><div> }</div><div> }</div></div><div>
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!