开发者

.NET: Problems creating email attachment from MemoryStream

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.

U开发者_JAVA百科nfortunately 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


Have you reset the position of the memory stream to 0 after writing your content to it?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜