Hi Friends...
Here I explain full procedure step by step
Step 1: Design a page using this code
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Send Mail</title>
<style type="text/css">
.auto-style1 {
height: 20px;
}
</style>
</head>
<body bordercolor="#6600FF">
<br />
<form id="form1" runat="server">
<div>
<table style="border: 3px solid #db6b11; padding: 20px;" align="center">
<tr>
<td colspan="2" align="center" class="auto-style1">
<p><font color="#db6b11" style="font-size: 25px;">C# JADU EMAIL SYSTEM </font></p>
</td>
</tr>
<tr>
<td>
<p><font color="#db6b11" style="font-size: 25px;">Gmail Username: -> </font></p>
</td>
<td>
<asp:TextBox ID="txtUsername" runat="server" BackColor="White" ForeColor="#db6b11"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<p><font color="#db6b11" style="font-size: 25px;">Gmail Password:--></font></p>
</td>
<td>
<asp:TextBox ID="txtpwd" runat="server" TextMode="Password" BackColor="White" ForeColor="#db6b11"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<p><font color="#db6b11" style="font-size: 25px;">Subject:-------------></font></p>
</td>
<td>
<asp:TextBox ID="txtSubject" runat="server" BackColor="White" ForeColor="#db6b11"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<p><font color="#db6b11" style="font-size: 25px;">To:-------------------></font></p>
</td>
<td>
<asp:TextBox ID="txtTo" runat="server" BackColor="White" ForeColor="#db6b11"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<p><font color="#db6b11" style="font-size: 25px;">Enter message:</font></p>
</td>
<td>
<asp:TextBox ID="txtBody" runat="server" TextMode="MultiLine" Columns="30" Rows="10" BackColor="White" ForeColor="#db6b11" Height="197px" Width="207px"></asp:TextBox>
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="btnSubmit" Text="Send" runat="server" OnClick="btnSubmit_Click" BackColor="#db6b11" ForeColor="#FFFFFF" Height="32px" Width="63px" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Your design will look like this
Step 2: Add some header files
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Security;
using System.Net.Mail;
Step 3: c# page code goes here
public partial class email : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
MailMessage Msg = new MailMessage();
// Sender e-mail address.
Msg.From = new MailAddress(txtUsername.Text);
// Recipient e-mail address.
Msg.To.Add(txtTo.Text);
Msg.Subject = txtSubject.Text;
Msg.Body = txtBody.Text;
// your remote SMTP server IP.
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential(txtUsername.Text, txtpwd.Text);
smtp.EnableSsl = true;
smtp.Send(Msg);
Msg = null;
Page.RegisterStartupScript("UserMsg", "<script>alert('Mail sent thank you...');if(alert){ window.location='SendMail.aspx';}</script>");
}
catch (Exception ex)
{
Console.WriteLine("{0} Exception caught.", ex);
}
}
}
0 comments:
Post a Comment