【发布时间】:2014-02-28 14:16:42
【问题描述】:
我想将 Windows Azure blob 存储中的 blob 附加到使用 SendGrid 发送的电子邮件中。我想指定附件的文件名(真正的文件名只是胡言乱语),afaik 迫使我将附件添加为流。
我的代码如下所示:
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");
文件从存储读取到内存流并添加附件似乎工作正常,但收到电子邮件后附件为 0 字节。
提前谢谢你。
【问题讨论】:
-
周末我意识到这(很可能)是与 SendGrid 相关的问题。将附件缓冲区的内容保存到文件中可以正常工作。我已经在 SendGrid 板上发布了这个,希望那里的任何人都能对此有所了解。 CopyTo 和 Write(缓冲区到缓冲区)都产生相同的结果。附件缓冲区正确,但接收到的文件不正确。
标签: azure stream azure-storage email-attachments sendgrid