How to send mail with attached file without store in local server
How to send mail with attached file without store in local server
string text = System.IO.File.ReadAllText(System.IO.Path.Combine(Server.MapPath("~/Mvc/Views/SinCairForm/EmailTemplate.cshtml")));
emailBody = Razor.Parse(text, new { Message = "hello", Serial=DateTime.Now.Year.ToString(), WebURL= "http://localhost:49557" });
MailMessage mail = new MailMessage("dev@convertium.com", "kesikan@convertium.com", "Subject", emailBody);
mail.IsBodyHtml = true;
System.IO.MemoryStream stream = new System.IO.MemoryStream();
System.IO.StreamWriter writer = new System.IO.StreamWriter(stream);
writer.Write(encryptedMsg);
writer.Flush();
stream.Position = 0;
mail.Attachments.Add(new Attachment(stream, "filename.txt", "text/plain"));
try
{
EmailSender.Get().Send(mail);
}
catch (Exception ex)
{
return Json(ex.Message, JsonRequestBehavior.AllowGet);
}
string text = System.IO.File.ReadAllText(System.IO.Path.Combine(Server.MapPath("~/Mvc/Views/SinCairForm/EmailTemplate.cshtml")));
emailBody = Razor.Parse(text, new { Message = "hello", Serial=DateTime.Now.Year.ToString(), WebURL= "http://localhost:49557" });
MailMessage mail = new MailMessage("dev@convertium.com", "kesikan@convertium.com", "Subject", emailBody);
mail.IsBodyHtml = true;
System.IO.MemoryStream stream = new System.IO.MemoryStream();
System.IO.StreamWriter writer = new System.IO.StreamWriter(stream);
writer.Write(encryptedMsg);
writer.Flush();
stream.Position = 0;
mail.Attachments.Add(new Attachment(stream, "filename.txt", "text/plain"));
try
{
EmailSender.Get().Send(mail);
}
catch (Exception ex)
{
return Json(ex.Message, JsonRequestBehavior.AllowGet);
}
Comments
Post a Comment