I have a HTML formatted email body content that comes from database table. When the mail is send, the body is to be formatted and rendered in users mail box in the way it is formatted and saved in db. (HTML formatting).
The code in database is :
<code></code><p>
This is body</p>
<p style="text-align: center;">
Formatted
<h2>
Body</h2>
<p style="margin-removed 40px;">
NEW BODY</p>
My code to send mail is :
public virtual MailMessage SendMailNotification(UserInfo item, DiagnosticTestMailContent diagnosticTestMailContent)
{
string body = diagnosticTestMailContent.Mail_Body;
var mailMessage = new MailMessage { Subject = diagnosticTestMailContent.Mail_Header + Kats.DAL.Connection.ProjectName().ToUpper() , Body = body };
mailMessage.From = new MailAddress(Kats.Helpers.FileSettings.GetAdminMail());
mailMessage.To.Add(item.Email);
ViewBag.MailBody = diagnosticTestMailContent.Mail_Body;
return mailMessage;
}
In users mail box, when they receive mail, they receive it this way instead of being formatted. How can I render a page in user mail box using HTML formatting instead of displaying all tags and content in mail box??
What I have tried:
I had created a method PopulateBody(mailMessage, viewName: "UserGroupDiagnostic"); to format the body using HTML formatting and send this body. But this way also it not working as required. The code for this is ;
public virtual MailMessage SendMailNotification(UserInfo item, DiagnosticTestMailContent diagnosticTestMailContent)
{
string body = diagnosticTestMailContent.Mail_Body;
var mailMessage = new MailMessage { Subject = diagnosticTestMailContent.Mail_Header + Kats.DAL.Connection.ProjectName().ToUpper() , Body = body };
mailMessage.From = new MailAddress(Kats.Helpers.FileSettings.GetAdminMail());
mailMessage.To.Add(item.Email);
ViewBag.MailBody = diagnosticTestMailContent.Mail_Body;
PopulateBody(mailMessage, viewName: "UserGroupDiagnostic");
return mailMessage;
}
--View to generate HTML content starts
@{
string mailBody = (string)ViewBag.MailBody;
string projName = Kats.DAL.Connection.ProjectName();
}
@mailBody
}
--View to generate HTML content ends