title: Error when attaching file to System.Net.Mail. How do I fix this error?
body: <p>Trying to send an email with an attachment.  However I am getting an error:  </p>
  
  <blockquote>
    <p>"Cannot convert from
    'System.Threading.Tasks.Task' to
    'System.Net.Mail.Attachment'</p>
  </blockquote>
  
  <p>My error occurs in the line             <code>Attachments.Add(GetAttachment(attachmentFileName));</code></p>
  
  <p>I have tried various conversions (see code) but I dont quite see what the issue is.  I know the solution is right in front of me but I dont see it.</p>
  
  <pre><code>public class NonFERosterEmail : BaseNotificationEmail&lt;OfferViewModel&gt;
  {
      public NonFERosterEmail(OfferViewModel vm, string emailList, string attachmentFileName) : base(vm)
      {
          To.AddRange(GetTo(emailList));
          Body = GetBody();
          Subject = GetSubject();
          //Attachments.Add(new Attachment(GetAttachment(attachmentFileName)));
          Attachments.Add(GetAttachment(attachmentFileName));
          From = new MailAddress(ConfigurationManager.AppSettings["RedirectEmailTo"]);
      }
  
      //public async Task&lt;List&lt;Attachment&gt;&gt; GetAttachment(string attachmentFileName)
      public async Task&lt;Attachment&gt; GetAttachment(string attachmentFileName)
      {
          //var ret = new List&lt;Attachment&gt;();
  
          CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["azureStorageAccount"]); 
          CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
          CloudBlobContainer container = blobClient.GetContainerReference("attachments");
          CloudBlockBlob blob = container.GetBlockBlobReference(attachmentFileName);
  
          var contentType = MimeMapping.GetMimeMapping(attachmentFileName);
          Stream target = new MemoryStream();
          await blob.DownloadToStreamAsync(target);
          target.Position = 0;
          //ret.Add(new Attachment(target, attachmentFileName, contentType));
  
          Attachment ret = new Attachment(target, attachmentFileName, contentType);
  
          return ret;
      }
  
  //remainder of code left out for brevity
  }
  </code></pre>
  
  <p>I expect the <code>GetAttachment</code> to return a correct Attachment object which would be added to the Mail object and sent successfully.</p>