using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace smtp1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
// Create the email
MailMessage mail = new MailMessage();
mail.To.Add(TextBox1.Text); // Recipient email (from input)
mail.From = new MailAddress("helloeventplanner2025@gmail.com");
mail.Subject = TextBox2.Text; // Subject from input
mail.Body = TextBox3.Text; // Body from input
// Configure SMTP
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.Credentials = new System.Net.NetworkCredential(
"helloeventplanner2025@gmail.com",
"lmrpnnsvmdlhexxp" // Gmail App Password
);
smtp.EnableSsl = true;
// Send email
smtp.Send(mail);
Label1.Text = "✅ Email sent successfully!";
}
catch (Exception ex)
{
Label1.Text = "❌ Error: " + ex.Message;
}
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="smtp1.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
To
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
Sub
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
Body
<asp:TextBox ID="TextBox3" runat="server" Height="129px" Width="255px"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Send" />
</div>
<asp:Label ID="Label1" runat="server" Text="Status"></asp:Label>
</form>
</body>
</html>
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