.NET: Problems creating email attachment from MemoryStream.
- by David
Hi all
I'm using the following method to create an attachment from a MemoryStream:
public void AddAttachment(Stream stream, string filename, string mimeType)
{
byte[] buffer = ((MemoryStream) stream).GetBuffer();
Attachment attachment = new Attachment(stream, filename, mimeType);
_mail.Attachments.Add(attachment);
}
Note that the first line is not necessary isn't necessary for the attachment functionality, it's just useful to have the byte[] handy during debugging so that I can see how big it is. (It generally has around 80,000 elements.)
The code runs fine and the email is sent. When Outlook receives the email, in the Inbox it displays the attachment symbol, but when you go into the email the attachment isn't there.
Unfortunately I don't have access to the mail server to find out more about the email, e.g. what the attachment looks like, its size etc.
Can anyone suggest what properties of the MemoryStream argument might tell me if it is in some way invalid for attachment? Or think of anything else I might try?
Thank you.
David