Send an email through website using code which is the much needy things in today’s website. Everybody needs to add this functionality like reset password , chat box, etc.
SOURCE CODE
CHECKOUT PAGE [DESIGN PAGE]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
public partial class Email : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSend_Click(object sender, EventArgs e)
{
try
{
MailMessage p = new MailMessage("email@gmail.com", txtEmail.Text);
p.Subject = "New Email";
p.Subject = txtMessage.Text;
p.Priority = MailPriority.High;
p.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential()
{
UserName = "email@gmail.com",
Password = "password"
};
smtp.EnableSsl = false;
smtp.Send(p);
lblmessage.Text = "Message Sent Successfully";
lblmessage.ForeColor = System.Drawing.Color.Green;
}
catch (Exception)
{
lblmessage.Text = "Message Failed";
lblmessage.ForeColor = System.Drawing.Color.Red;
}
}
}