Send Email from worker role (Azure) with attachment in c#
Posted
by
simplyvaibh
on Stack Overflow
See other posts from Stack Overflow
or by simplyvaibh
Published on 2011-01-09T05:19:20Z
Indexed on
2011/01/09
9:53 UTC
Read the original article
Hit count: 402
I am trying to send an email(in c#) from worker role(Azure) with an attachment(from blob storage). I am able to send an email but attachment(word document) is blank. The following function is called from worker role.
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();
}
Please tell me where I am doing wrong?
© Stack Overflow or respective owner