Home > ASP.Net > Send Email with Dynamic Content

Send Email with Dynamic Content


Hi

try this example :

1) Create MyContent.htm

Hi <yourfriendname>,

Thank you for sending this email. See you soon.

Good Bye,

<yourname>
 <dateyousendthisemail>

2) Create Default.aspx page

Add one html file named MyContent.html.
Copy and paste the above message to the html file.
Then come to Default.aspx file,
add two textboxes and rename it as txtMyName and txtFriendName.
Add a button and rename it as cmdSendEmail and change
the Button’s Text to Send Email.

in code behind :-

using System.Web.Mail;
using System.IO;
try
{
StreamReader sr=new StreamReader(“MyContent.htm”);
sr = File.OpenText(“MyContent.htm”);
string result = sr.ReadToEnd();
sr.Close();
}
catch(Exception ex)
{
Response.Write(ex.Message);
return;
}
string MessageBody=result.Replace("<YourFriendName>", txtFriendName.Text);
MessageBody=MessageBody.Replace("<YourName>", txtMyName.Text);
MessageBody= MessageBody.Replace("<DateYouSendThisEmail>", DateTime.Today.ToString());
MailMessage mail = new MailMessage();
mail.Body = MessageBody;
mail.BodyFormat = MailFormat.Html;
mail.From = “YOUR EMAIL ID”;
mail.To = “YOUR FRIEND’S EMAIL ID”;
mail.Subject = "Dynamic Content Email From "+ txtMyName.Text;
SmtpMail.SmtpServer = “your email server”;
SmtpMail.Send(mail);

Hope this helps

Good Luck

Advertisements
Categories: ASP.Net
  1. February 16, 2009 at 9:18 am

  2. February 19, 2009 at 10:46 am

    Anna

  3. March 13, 2009 at 9:49 am

  4. April 27, 2009 at 10:53 am

    Thanks

  5. May 8, 2009 at 11:51 am

    Thanks

  6. December 14, 2009 at 9:13 am

  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: