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 : *****
Labels: .Net Tutorials, Aspnet, C#, CSharp, Tanisha
5 Comments:
Very Cleared Thanks......
Thanks For Sharing
Good One.......
Good One.......
Thank U
Post a Comment
Subscribe to Post Comments [Atom]
<< Home