My contemplations and diurnal novelties are publicized here

You can simply send an email using the template as an html using following code

private void SendEmail()
string subject = “Email Subject”;
AlternateView htmlView = GetEmailViewFromTemplateTemplate(“Wahab Hussain”);

System.Net.Mail.MailMessage Msg = new System.Net.Mail.MailMessage();
System.Net.NetworkCredential SmtpUser = new System.Net.NetworkCredential();
SmtpUser.UserName = “”;
SmtpUser.Password = “YourAccountPassword”;

System.Net.Mail.MailAddress fromAddress = new System.Net.Mail.MailAddress(“”, “Your Name”);
Msg.From = fromAddress;

Msg.Subject = subject;
Msg.Body = null;
Msg.IsBodyHtml = true;

System.Net.Mail.SmtpClient SmtpServer = new System.Net.Mail.SmtpClient();
SmtpServer.Credentials = SmtpUser;
SmtpServer.Port = 587;
SmtpServer.EnableSsl = true;
SmtpServer.Host = “”;

catch (Exception ex)


private AlternateView GetEmailViewFromTemplateTemplate(string toName)
StringBuilder emailTemplate = new StringBuilder();
string filePath = Server.MapPath(“emailTemplate.htm”);

AlternateView htmlView = null;
if (System.IO.File.Exists(filePath))
emailTemplate = new StringBuilder(System.IO.File.ReadAllText(filePath));
emailTemplate.Replace(“<%Name%>”, toName);

htmlView = AlternateView.CreateAlternateViewFromString(emailTemplate.ToString(), null, “text/html”);


return htmlView;

protected void btnSendEmail_Click(object sender, EventArgs e)

Here is the template

 <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”&gt;
<html xmlns=””&gt;
Hello <%Name%>
How are you? you have received an email via email templating.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: