I'm trying to attach a file that's provided in a byte array as an attachment in an email but I'm getting the following error:
Exception: Failure sending mail.
InnerException: Stream does not support reading.
But that's it. Not much to go with!
I'm attaching the byte array file as follows:
using (MailMessage message = new MailMessage())
{
message.Subject = subject;
....
using (MemoryStream ms = new MemoryStream(attachment.Data))
{
message.Attachments.Add(new System.Net.Mail.Attachment(ms, attachment.Name));
}
}
Note that the attachment
variable is our own class which just provides additional information about the file including .Data
which contains the byte array representing the file.
Any ideas?
Thanks.