Design Page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="king.aspx.cs" Inherits="king" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
height: 23px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div align=center>
<asp:Label ID="Label1" runat="server" BackColor="#99CC00" Font-Bold="True"
Font-Size="X-Large" Text="CRM Sample WebSite"></asp:Label>
<br />
<table style="width: 46%;">
<tr>
<td class="style1" colspan="2">
Mail Services</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="To"></asp:Label>
</td>
<td>
<asp:TextBox ID="toaddress" runat="server" Width="293px"
></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label3" runat="server" Text="CC"></asp:Label>
</td>
<td>
<asp:TextBox ID="ccaddress" runat="server" Width="295px"
></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label4" runat="server" Text="BCC"></asp:Label>
</td>
<td>
<asp:TextBox ID="bccaddress" runat="server"
Width="295px" ontextchanged="bccaddress_TextChanged"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label5" runat="server" Text="Subject"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtsubject" runat="server"
Width="295px" ontextchanged="txtsubject_TextChanged1"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label6" runat="server" Text="Message"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtmsg" runat="server" Height="227px" Width="446px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Send" />
<asp:Label ID="Label7" runat="server"></asp:Label>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Coding Page:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Mail;
using System.Net.Mail;
public partial class king : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void SendMail()
{
var fromAddress = "iyngarantce@gmail.com";
var toAddress = toaddress.Text.ToString();
const string fromPassword = "";
string subject = txtsubject.Text.ToString();
string body = txtmsg.Text.ToString();
var smtp = new System.Net.Mail.SmtpClient();
{
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new System.Net.NetworkCredential(fromAddress, fromPassword);
smtp.Timeout = 20000;
}
smtp.Send(fromAddress, toAddress, subject, body);
}
protected void Button1_Click(object sender, EventArgs e)
{ try
{
SendMail();
Label7.Text = "Your Comments after sending the mail";
txtsubject.Text = "";
toaddress.Text = "";
ccaddress.Text = "";
txtmsg.Text = "";
}
catch (Exception) { }
}
protected void txtsubject_TextChanged(object sender, EventArgs e)
{
}
protected void txtmsg_TextChanged(object sender, EventArgs e)
{
}
protected void bccaddress_TextChanged(object sender, EventArgs e)
{
}
protected void txtsubject_TextChanged1(object sender, EventArgs e)
{
}
}
No comments:
Post a Comment