Send E-mail with Dynamic Body

This Article is helpful to understand this:- 1)basic part of E-mail. 2)how to make dynamic body of email. 3)send mail with SMTP server. I explain clearly to create dynamic Body part of E-mail Content.

Parts of an email message


The message headers contain information concerning the sender and recipients. The exact content of mail headers can vary depending on the email system that generated the message. Generally, headers contain the following information:


Sender (From).
Date and time received (On).
Recipient (To:).
Recipient email address.


The body of a message contains text that is the actual content, such as "Employees who are eligible for the new health care program should contact their supervisors by next Friday if they want to switch." The message body also may include signatures or automatically generated text that is inserted by the sender's email system.


Attachments are optional and include any separate files that may be part of the message.

In the SMTP standard, the body is the full email message. The header here is only information servers need to deliver the message.............

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

Then after add what you want to show in body part of email code as per it into your HTML Page.
here i want to show 4 paramaters,

Client Name:@@Client_Name@@
Event Name:@@Event_Name@@

for get value of dynamically of this four parameters,we have to use this methos.

protected void getDataforemail()

EventManagerDataContext db = new EventManagerDataContext();

var q = (from a in db.EMR_EVENTs
join b in db.EMR_CLIENTs on a.ClientID equals b.ClientID
select new
EventID = a.EventID,
Client_Name = b.Name,
Event_Name = a.Name,

catch (Exception)


now you have to call this function only.and you will get value of this parameters dynamically from database.

now put this code into your aspx.cs file.

protected void getDynamicbodyforemail()
StreamReader reader = new StreamReader(Server.MapPath("~/HTMLPage1.htm"));
string readFile = reader.ReadToEnd();
string myString = "";
myString = readFile;

myString = myString.Replace("$$Client_Name$$", Client_Name);
myString = myString.Replace("$$Event_Name$$", Event_Name);
myString = myString.Replace("$$Event_Id$$", EventID);
myString = myString.Replace("$$Activation_Code$$", "");

MailMessage Msg = new MailMessage();
MailAddress fromMail = new MailAddress("");
// Sender e-mail address.
Msg.From = fromMail;
// Recipient e-mail address.
// Subject of e-mail
Msg.Subject = "Send Mail with HTML File";
Msg.Body = myString.ToString();
Msg.IsBodyHtml = true;

var smtp = new System.Net.Mail.SmtpClient();
smtp.Host = "";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(fromMail.ToString(), "your password");
smtp.Timeout = 20000;






  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: