aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Send HTML File or Page as Email Body in using C#, VB.NET

May 11, 2015

Here I will explain how to send html page or file as email body in using C# and VB.NET.


In previous article I explained Send Mail in, Send mail with images using gmail credentials, Send mail with attachment in and many articles relating to JQuery,, SQL Server etc. Now I will explain how to send html page as email body in using C# and VB.NET.

To implement this concept first create new web application >> Right click on your application >> Select Add New item >> Select HTML Page and click OK

Once HTML page added to your application open it and write the following code in HTMLPage.htm page

<html xmlns="">
<head><title>HTML Page to Send Mail </title></head>
<img src = "" /><br /><br />
<div style = "border-top:3px solid #EB5E00">&nbsp;</div>
<table style="border:1px solid #EB5E00">
<td><b><span style = "font-family:Arial;font-size:10pt">Admin:</span></b></td>
<td><b><span style = "font-family:Arial;font-size:10pt">CompanyName:</span></b></td>
<td><b><span style = "font-family:Arial;font-size:10pt">EMail:</span></b></td>
<td><b><span style = "font-family:Arial;font-size:10pt">Website:</span></b></td>
<p><span style = "font-family:Arial;font-size:10pt">To know more about, please visit -  </span> </p>
<span style = "font-family:Arial;font-size:10pt">Thanks</span>
<br />
<b><span style = "font-family:Arial;font-size:10pt">Aspdotnet-Suresh</span></b>
Now open your Default.aspx page and write the following code

<html xmlns="">
<head runat="server">
<title>Send HTML page as email body in</title>
<form id="form1" runat="server">
<asp:Button ID="btnSend" Text="Send Mail" runat="server" onclick="btnSend_Click" />

Now add the following namespaces in code behind

C# Code

using System;
using System.Net.Mail;
using System.IO;
using System.Configuration;

After add namespaces write the following code in code behind

protected void Page_Load(object sender, EventArgs e)

protected void btnSend_Click(object sender, EventArgs e)
// Method Which is used to Get HTML File and replace HTML File values with dynamic values and send mail
public void SendHTMLMail()
StreamReader reader = new StreamReader(Server.MapPath("~/HTMLPage.htm"));
string readFile = reader.ReadToEnd();
string myString = "";
myString = readFile;
myString = myString.Replace("$$Admin$$", "Suresh Dasari");
myString = myString.Replace("$$CompanyName$$", "Dasari Group");
myString = myString.Replace("$$Email$$", "");
myString = myString.Replace("$$Website$$", "");
MailMessage Msg = new MailMessage();
MailAddress fromMail = new MailAddress("");
// Sender e-mail address.
Msg.From = fromMail;
// Recipient e-mail address.
Msg.To.Add(new MailAddress(""));
// Subject of e-mail
Msg.Subject = "Send Mail with HTML File";
Msg.Body = myString.ToString();
Msg.IsBodyHtml = true;
string sSmtpServer = "";
sSmtpServer = "";
SmtpClient a = new SmtpClient();
a.Host = sSmtpServer;


Imports System.Net.Mail
Imports System.IO
Imports System.Configuration
Partial Class VBSample
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs)

End Sub
Protected Sub btnSend_Click(sender As Object, e As EventArgs)
End Sub
' Method Which is used to Get HTML File and replace HTML File values with dynamic values and send mail
Public Sub SendHTMLMail()
Dim reader As New StreamReader(Server.MapPath("~/HTMLPage.htm"))
Dim readFile As String = reader.ReadToEnd()
Dim myString As String = ""
myString = readFile
myString = myString.Replace("$$Admin$$", "Suresh Dasari")
myString = myString.Replace("$$CompanyName$$", "Dasari Group")
myString = myString.Replace("$$Email$$", "")
myString = myString.Replace("$$Website$$", "")
Dim Msg As New MailMessage()
Dim fromMail As New MailAddress("")
' Sender e-mail address.
Msg.From = fromMail
' Recipient e-mail address.
Msg.[To].Add(New MailAddress(""))
' Subject of e-mail
Msg.Subject = "Send Mail with HTML File"
Msg.Body = myString.ToString()
Msg.IsBodyHtml = True
Dim sSmtpServer As String = ""
sSmtpServer = ""
Dim a As New SmtpClient()
a.Host = sSmtpServer
End Sub
End Class


Download Sample Code Attached

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Give your Valuable Comments

Other Related Posts

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.