我想从工作人员角色(Azure)与附件(从BLOB存储)发送电子邮件(在C#中)。 我可以发送电子邮件,但附件(word文档)为空。 从worker角色调用以下函数。发送电子邮件从工作人员角色(Azure)与附件在C#
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("[email protected]", "[email protected]");
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("[email protected]", Password);
client.Send(Email);
fs.Flush();
fs.Close();
Email.Dispose();
}
请告诉我我在做什么错?
得到解决方案 byte [] file = blob.DownloadByteArray(); Attachment attach = new Attachment(new MemoryStream(file),“Report.doc”); 而不是使用FileStream中使用的字节数组和MemoryStream和它的工作正常。 感谢您的回复。 – simplyvaibh 2011-01-10 05:09:50