title: Retrieving a stored email attachment as a byte[] from Rabbit MQ doesn't send email
body: <p>I'm convert an svg object to a byte[] and storing this in a queue with the following class</p>
  
  <pre><code>public class MailMessage
  {  
      public string AttachmentName { get; set; }    
      public byte[] Attachment { get; set; }
  }
  </code></pre>
  
  <p>However the email never gets sent. I'm thinking that the attachment is corrupt because if we skip adding the attachment to the email then it sends fine.</p>
  
  <pre><code>using (var stream = new MemoryStream(attachment))
  {
    var mailMessage = new MailMessage(this.from, new MailAddress(recipient)) { Subject = subject, Body = message };
  
    // this is the line which if commented out allows the email to be sent 
    mailMessage.Attachments.Add(new Attachment(stream, filename));
  
    MailSender().SendAsync(mailMessage, null);
  }
  </code></pre>
  
  <p>A co-worker suggested that the byte[] may have been compromised due to the way rabbit stores messages and to therefore base64 encode the byte[] before storing it using the built in functions</p>
  
  <pre><code>Convert.ToBase64String(bytes)
  
  Convert.FromBase64String(message.Attachment) // to retrieve
  </code></pre>
  
  <p>However that didn't work either.</p>
  
  <p>Can anyone think why this is failing to send and think of any work-arounds. </p>
  
  <p>I'm contemplating storing the image in the database and deleting it once the email is sent, but this is a last resource.</p>