SendGrid: How to attach a file from Azure blob storage?

后端 未结 2 1042
闹比i
闹比i 2021-01-14 12:10

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

相关标签:
2条回答
  • 2021-01-14 12:36

    This has probably already been solved, but you need to make sure that you 'rewind' the stream back to the beginning using Seek. Sample code below.

    stream.Seek(0, SeekOrigin.Begin);
    sendGrid.AddAttachment(stream, "name");
    
    0 讨论(0)
  • 2021-01-14 13:00

    Even though I am not sure how AddAttachment API works, please note that your MemoryStream's position will be set to its length at the end of the download. Hence, you might need to seek it to the beginning before calling AddAttachment.

    var ms = new MemoryStream();
    blob.DownloadToStream(ms);
    ms.Position = 0;
    msg.AddAttachment(ms, "originalfilename.png");
    
    0 讨论(0)
提交回复
热议问题