Send Email using ASP.Net and C#

Posted by Prince | 7:54:00 PM | | 0 comments »

Send Email from your GMAIL account using ASP.Net and C#:
                                                    This article is provide a demo for send Emails  from your GMAIL account using ASP.Net and C#:
First create an aspx file named "SendGmail.aspx" with required input controls and action buttons. Please refer the below screen shot.

Give the id for from textbox as "txtFrom" and "txtTo", "txtSubject", "txtMessage"  respectively.
Then add the following code into the "Send Email" button's OnClick method in thecode behind. Before appropriate name space (if you need).

protected void btnSendEmail_Click(object sender, EventArgs e)
//Create Mail Message Object with content that you want to send with mail.
System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage(txtFromMail.Text, txtToMail.Text, txtSubject.Text, txtMeaasge.Text);
mailMessage.IsBodyHtml = false;      
//Proper Authentication Details need to be passed when sending email from gmail
System.Net.NetworkCredential mailAuthentication = new
//Smtp Mail server of Gmail is "" and it uses port no. 587
        //For different server like yahoo this details changes and you can
        //get it from respective server.
System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient(""587);
//Enable SSL
mailClient.EnableSsl = true;
mailClient.UseDefaultCredentials = false;
mailClient.Credentials mailAuthentication;
You can download full code for send email using csharp from here

Please leave some comment, if this post useful to you.


Related Posts Plugin for WordPress, Blogger...