我在使用SendGrid发送的电子邮件中附加了Windows Azure Blob存储中的Blob。我想指定附件的文件名(真实文件名称只是mumbo jumbo),afaik强制我将该附件添加为流。SendGrid:如何从Azure blob存储中附加文件?
我的代码如下所示:
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(缓冲区到缓冲区)产生相同的结果。附件缓冲区正确,但收到的文件不正确。 – HSBallina