Friday, December 21, 2007

Sending Emails with Dynamic Content

I want the message of the email to like
Hi , Thank you for sending this email. See you soon. Good Bye,

Code :
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("", txtFriendName.Text);
MessageBody=MessageBody.Replace("", txtMyName.Text);
MessageBody= MessageBody.Replace("",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);

No comments: