title: SendGrid: How to attach a file from Azure blob storage?
body: <p>I have blobs in Windows Azure blob storage that I'd like to attach to emails sent with SendGrid. I'd like to specify the file name for the attachment (real file names are just mumbo jumbo) which afaik forces me to add the attachment as a stream.</p>
  
  <p>My code looks like this:</p>
  
  <pre><code>var msg = SendGrid.GetInstance();
  // Code for adding sender, recipient etc...
  var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["storage"].ConnectionString);
  var blobClient = storageAccount.CreateCloudBlobClient();
  var container = blobClient.GetContainerReference(typeName);
  var blob = container.GetBlockBlobReference("somefile.png");
  var ms = new MemoryStream();
  blob.DownloadToStream(ms);
  msg.AddAttachment(ms, "originalfilename.png");
  </code></pre>
  
  <p>The file gets read from the storage to the memory stream and adding the attachment seems to work fine but after receiving the email the attached file is 0 bytes.</p>
  
  <p>Thank you in advance.</p>