I am trying to send an email with an attachment (attachment should get downloaded from blob storage) from worker role using c#.net.
I am able to send an email without attachment, but when I am trying with attachment the I am receiving blank attachment.
What I am trying here is that I am uploading .doc file in blob storage and in worker role trying to send that .doc file as a attachment in email.
Please find the below function which I am calling 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);
FileStream fs = new FileStream("demo.doc", FileMode.OpenOrCreate);
Attachment attach = new Attachment(fs,"Report.doc");
System.Net.Mail.MailMessage Email = new System.Net.Mail.MailMessage("User@hotmail.com", "email@example.com");
Email.Subject = "Text fax send via email";
Email.Subject = "Subject Of email";
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("User@gmail.com", "Password");
Please tell the solution for above scenario. How should I send an email with an attachment from worker role?
Thanks in advance
Got the solution...
byte file= blob.DownloadByteArray();
Attachment attach = new Attachment(new MemoryStream(file), "Report.doc");
Instead of using FileStream used Byte array and MemoryStream and its working fine.
Thanks for your replies.
Microsoft is conducting an online survey to understand your opinion of the Msdn Web site. If you choose to participate, the online survey will be presented to you when you leave the Msdn Web site.
Would you like to participate?