Blog
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog
Report Abuse Form
Reason:    
 

Home >> ASP.Net & Web Forms >> Sending mail in ASP.NET.
Sending mail in ASP.NET.

Hi...... In this blog I will tell you that how to send mail using ASP.NET.
Views: 2510     Comments: 0
by Awadhendra Tiwari on 5/23/2011

Sending mail message using SmtpClient and MailMessage class

Here in this blog I will tell you that how to send mail to users using SmtpClient and MailMessage class. Here I have created a small function which is used to send mail. One thing important that before using this method your application should be hosted on some webserver.

/// <summary>

        /// This method will be used to send mail to client

        /// by using Smtp and MailMessage class.

        /// </summary>

        /// <param name="sFrom"></param>

        /// <param name="sTo"></param>

        /// <param name="sBcc"></param>

        /// <param name="sCC"></param>

        /// <param name="sSubject"></param>

        /// <param name="sBody"></param>

        public static void sendMail(string sFrom, string sTo, string sBcc, string sCC, string sSubject, string sBody)

        {

            MailMessage message = new MailMessage();          //Here we will create object of MailMessage class.

            message.From = new MailAddress(sFrom);       //Initilize From in mail address.

            message.To.Add(new MailAddress(sTo));        //Initilize To in mail address.

           

            if (!string.IsNullOrEmpty(sBcc))           //Check whether sBcc is not empty.

            {

                message.Bcc.Add(new MailAddress(sBcc));    //Add sBcc in mail address.

            }

            if (!string.IsNullOrEmpty(sCC))          //Check whether sCC is not empty.

            {

                message.CC.Add(new MailAddress(sCC));      //Add CC in mail address.

            }

            message.Subject = sSubject;        //Add subject in mail message.

            message.Body = sBody;            //Add body in mail message.

            message.IsBodyHtml = true;             

            message.Priority = MailPriority.High;   //Set priority of mail message.

            SmtpClient client = new SmtpClient();                  //Create an object of Smtp client.

            client.Send(message);            //Send message by using send() method.

        }

Title :  
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
      
 
Report Abuse Form
Reason:    
 
Latest Article
    
    
    
    
    
    
    
    
    
    
More...
Latest Blogs by Awadhendra Tiwari
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed Articles
    
    
    
    
    
    
    
    
    
    
Top Viewed Blogs
    
    
    
    
    
    
    
    
    
    
Latest Interview Questions
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 3055
Dudelabs
Copyright © 2009 - 2012 MindStick. All Rights Reserved.