.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 >> Email >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Mail Coding With Domain Network CredMailMessage mailMsg = new MailMessage(); mailMsg.entials

Posted By:BangaruBabuPureti       Posted Date: May 13, 2010    Points: 5    Category: Email    URL: http://www.dotnetspark.com  

This Code Snippet Illustrates Sending Mail By Using System.Net.Mail Namespace
 

/*Import The Name Space in Cs Code*/

using System.Net.Mail; /*create Object For MailMessage*/
MailMessage mailMsg = new MailMessage();
/*Asign New From Address as a String */

mailMsg.From = new MailAddress(FromAddress);
/*Creating Instance For The New Address*/

mailMsg.To.Add(new MailAddress(ToAddress));

/*Assign Subject To That MailMessage Instance*/

mailMsg.Subject = Subject;
/*This Line Just Gives To Print Body Message As A Plaint Text*/
System.Net.Mail.AlternateView plainView = System.Net.Mail.AlternateView.CreateAlternateViewFromString (System.Text.RegularExpressions.Regex.Replace(BodyText, @"<(.|\n)*?>", string.Empty), null, "text/plain");
/*This Line Just Gives To Print Body Message As A HTML Text*/
System.Net.Mail.AlternateView htmlView =System.Net.Mail.AlternateView.CreateAlternateViewFromString(BodyText, null, "text/html"); mailMsg.AlternateViews.Add(plainView); mailMsg.AlternateViews.Add(htmlView);
/*smptConfiguration*/
SmtpClient smtp = new SmtpClient(); smtp.Port = 25; smtp.Host = "mail.saiastro.in"; smtp.UseDefaultCredentials = true; smtp.Credentials = new System.Net.NetworkCredential("info@saiastro.in", "passwordFor TheDomain"); ; smtp.EnableSsl = false; smtp.Send(mailMsg);


     

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