Send Email

You must have to use Gmail ID as From Email ID.

USE: using System.Net.Mail; // Namespace

OnSendMail Button Click Event :

try
{
SmtpClient obj = new SmtpClient(“smtp.gmail.com”);
obj.Credentials = new System.Net.NetworkCredential(“your@gmail.com”, “password”);
obj.Port = 587;
obj.Host = “smtp.gmail.com”;
obj.EnableSsl = true;

MailMessage message = new MailMessage(“your@gmail.com”,”to@yahoo.com”);
message.Subject = txtSUB.Text; // subject textbox’s text
message.Body = txtMSG.Text; // Message textbox’s text
obj.Send(message);
Response.Write(“Mail Successfully send”);
}
catch (SmtpException ex)
{
Response.Write(ex.Message.ToString());
}

Share