我正在尝试从辅助角色(Azure)发送一封带有附件(来自blob存储)的电子邮件(在c#中)。 我可以发送电子邮件,但附件(word 文档)为空。 从辅助角色调用以下函数。
public void sendMail(string blobName)
{
InitStorage();//Initialize the storage
var storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
container = blobStorage.GetContainerReference("Container Name");
CloudBlockBlob blob = container.GetBlockBlobReference(blobName);
if (File.Exists("demo.doc"))
File.Delete("demo.doc");
FileStream fs = new FileStream("demo.doc", FileMode.OpenOrCreate);
blob.DownloadToStream(fs);
Attachment attach = new Attachment(fs,"Report.doc");
System.Net.Mail.MailMessage Email = new System.Net.Mail.MailMessage("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d184a2b4a391b9bea5bcb0b8bdffb2bebc" rel="noreferrer noopener nofollow">[email protected]</a>", "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="722701170032151f131b1e5c111d1f" rel="noreferrer noopener nofollow">[email protected]</a>");
Email.Subject = "Text fax send via email";
Email.Subject = "Subject Of email";
Email.Attachments.Add(attach);
Email.Body = "Body of email";
System.Net.Mail.SmtpClient client = new SmtpClient("smtp.live.com", 25);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.Credentials = new NetworkCredential("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="396c4a5c4b7951564d54585055175a5654" rel="noreferrer noopener nofollow">[email protected]</a>", Password);
client.Send(Email);
fs.Flush();
fs.Close();
Email.Dispose();
}
请告诉我哪里做错了?
最佳答案
在附加创建 Attachment
对象之前,我会尝试执行 fs.Position = 0;
操作。
可能发生的情况是,它试图从流中的当前位置读取,而该流位于末尾,因此它什么也没读取。
关于email - 从辅助角色 (Azure) 发送带有 C# 附件的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4637822/