hi
How to send Mail in my asp.net C# application i need perfect code
running condition code
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Vijay YadavRank #1,637 · 943 reputationPosted Mar 14, 2011, 11:09 PM EDT
you can write this code on button click
string from = txtFrom.Text; //Replace this with your whom you want to send the mail
string to = txtTo.Text; //Replace this with the Email Address to whom you want to send the mail
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add(to);
mail.From = new MailAddress(from, "Any Name", System.Text.Encoding.UTF8);
mail.Bcc.Add(txtBcc.Text);
mail.CC.Add(txtCc.Text);
mail.Subject = txtSubject.Text;
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = txtMessage.Text;
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
//Add the Creddentials- use your own email id and password
client.Credentials = new System.Net.NetworkCredential(username, password);// here you have to write your gmail username and password
client.Port = 587; // Gmail works on this port
client.Host = "smtp.gmail.com";
client.EnableSsl = true; //Gmail works on Server Secured Layer
client.Send(mail);
Soft CornerRank #1,221 · 1.5K reputationPosted Mar 14, 2011, 11:11 PM EDT
Also Check Our recommended articles at right hand side,
Sending Mail in ASP.NET using C#
Suthish NairRank #92 · 22.8K reputationPosted Mar 16, 2011, 11:33 AM EDT