views:

88

answers:

1

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

+1  A: 

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

David M
That's it! That's what it was!Thank you so much.
David
No problem. Glad it was that simple.
David M
Interesting concert schedule by the way. Where's the New World Symphony or Star Wars theme? ;)
David
New World Symphony I think is down for June 2011, and we did Star Wars three or four years ago... ;)
David M