using System;
using System.Net;
using System.Net.Mail;
using System.Web.UI;
namespace SmtpDemo
{
public partial class WebForm1 : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSend_Click(object sender, EventArgs e)
{
try
{
MailMessage mail = new MailMessage();
mail.To.Add(txtTo.Text.Trim());
mail.From = new MailAddress(txtFrom.Text.Trim());
mail.Subject = txtSubject.Text.Trim();
mail.Body = txtBody.Text.Trim();
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.Credentials = new NetworkCredential("arunteja2385@gmail.com", "xvjz ydjj zwob aekd");
smtp.EnableSsl = true;
smtp.Send(mail);
lblMessage.ForeColor = System.Drawing.Color.Green;
lblMessage.Text = "Email sent successfully!";
}
catch (Exception ex)
{
lblMessage.ForeColor = System.Drawing.Color.Red;
lblMessage.Text = "Error sending email: " + ex.Message;
}
}
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter