Hi friends,in this post I would like to explain how to send email in Asp.Net.
For this I am taking 3 TextBoxes(For ToAddress,Subject & Body) and a Button control.
For working with emails you need to add the following namespace:
using System.Net.Mail;
Then code under Send Button Click Event:
protected void btnSendEmail_Click(object sender, EventArgs e) {
MailMessage mssg = newMailMessage(); mssg.From = new MailAddress("yourgmailid@gmail.com"); mssg.To.Add(txtToAddtess.Text); mssg.Subject = txtSubject.Text; mssg.IsBodyHtml = true; mssg.Body = txtBody.Text; mssg.Priority = MailPriority.High; System.Net.Mail.SmtpClient client = new system.Net.Mail.SmtpClient(); client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential("yourgmailid@gmail.com", "yourgmailpassword"); client.Port = 587; client.Host = "smtp.gmail.com"; client.EnableSsl = true; object userstate = mssg; client.Send(mssg); lblDisplayMessage.Text = "Mail Sent Successfully.";//label for displaying message. }
Then email will be sent to destination person
Thank You...
For this I am taking 3 TextBoxes(For ToAddress,Subject & Body) and a Button control.
For working with emails you need to add the following namespace:
using System.Net.Mail;
Then code under Send Button Click Event:
protected void btnSendEmail_Click(object sender, EventArgs e) {
MailMessage mssg = newMailMessage(); mssg.From = new MailAddress("yourgmailid@gmail.com"); mssg.To.Add(txtToAddtess.Text); mssg.Subject = txtSubject.Text; mssg.IsBodyHtml = true; mssg.Body = txtBody.Text; mssg.Priority = MailPriority.High; System.Net.Mail.SmtpClient client = new system.Net.Mail.SmtpClient(); client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential("yourgmailid@gmail.com", "yourgmailpassword"); client.Port = 587; client.Host = "smtp.gmail.com"; client.EnableSsl = true; object userstate = mssg; client.Send(mssg); lblDisplayMessage.Text = "Mail Sent Successfully.";//label for displaying message. }
Then email will be sent to destination person
Thank You...