.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

HTML Mail in ASP.NET

Posted By:Athira Sreejith       Posted Date: February 22, 2009    Points: 5    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  
 

HTML Mail in ASP.NET: Sometime we need to format mail content in heml format below is the sample code.

string _date = DateTime.Now.ToString("MMM") + "'" + DateTime.Now.Day.ToString() + " " + DateTime.Now.Year.ToString();

System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage();

StringBuilder recentXMl = new StringBuilder();

//User requestUser = User.GetUser(Convert.ToInt16(requesterID));

string txt = txtSubject.Text;

string recentNode = @""

+ "" + _date + ""

+ "" + De.Key + "," + ""

+ "" + "" + txtName.Text + "" + txt + ""

+ "";

recentXMl.Append(recentNode);

StringWriter sw = new StringWriter();

StringReader strReader = new StringReader(recentXMl.ToString());

XmlTextReader reader = new XmlTextReader(strReader);

XPathDocument createHeaderDoc = new XPathDocument(reader);

string xslFileName = "../xsl/SwapResponse.xsl";

XslTransform transform = new XslTransform();

transform.Load(HttpContext.Current.Server.MapPath(xslFileName));

transform.Transform(createHeaderDoc, null, sw, null);

try

{

mail.BodyFormat = System.Web.Mail.MailFormat.Html;

mail.To = De.Value.ToString();

mail.From = txtRespondEmail.Text;

mail.Subject = txtSubject.Text;

mail.Body = sw.ToString();

//Response.Write(sw.ToString());

System.Web.Mail.SmtpMail.Send(mail);

}

catch(Exception ex)

{

//Response.Write(ex.Message.ToString());

}


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend