Friday, May 6, 2011

How to Send a Mail Using Aspnet with C#

Hi Friends, In this article i would like to explain the procedure of Sending a mail in Asp net with c#. I am already explained the procedure of sending a mail with multiple attachments.Now ,In this article i am going to explain only sending a mail in a particular format using Aspnet and C#

Just Follow the steps

First,open the Default.aspx page

Next,ADD some controls from Your Toolbox.that is,Add three Text boxes (one for From Address,another for TO Address and Third one for Body of the message)


Next,Add one button and change the ID of the button is btn_send

Next,Open the code page that is Default.aspx.cs

Next ,add this namespace using System.Net.Mail

Next,write the following code in the button event

protected void btn_send_Click(object sender, EventArgs e)
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();

msg.From = new MailAddress("Write your Gmail address");

msg.To.Add(txt_email.Text);//Text Box for To Address

msg.Subject = txt_name.Text; //Text Box for subject

msg.IsBodyHtml = true;

msg.Body = txt_comment.Text;//Text Box for body

msg.Priority = MailPriority.High;

System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);

client.UseDefaultCredentials = false;

client.Credentials = new System.Net.NetworkCredential("yourGmail ID", "yourGmail Password");

client.Port = 587;

client.Host = "smtp.gmail.com";

client.EnableSsl = true;

object userstate = msg;

client.Send(msg);

}

In the above code,change the following lines

Write your Gmail address : abc@gmail.com

Gmail ID : abc

Gmail ID : *****

That's it..

Check the Next Tutorial Send Email with Mulitple attachments
developercode
About the Author
Sayyad is a Software Engineer, Blogger and Founder of Developers Code from India.His articles mainly focus on .Net (Web and Windows based applications), Mobile Technologies (Android,IPhone,BlackBerry) and SEO.

Labels: , , , ,

5 Comments:

At May 6, 2011 at 12:56 PM , Anonymous Anonymous said...

Very Cleared Thanks......

 
At May 6, 2011 at 12:57 PM , Anonymous Anonymous said...

Thanks For Sharing

 
At June 9, 2011 at 12:39 PM , Anonymous Anonymous said...

Good One.......

 
At June 28, 2011 at 10:17 AM , Anonymous Anonymous said...

Good One.......

 
At December 28, 2013 at 6:10 PM , Anonymous Anonymous said...

Thank U

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home