我想從工作人員角色(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