Posted by: bhuvanvel | March 29, 2008

sending Mails

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Web.Mail;

namespace emailexample

{

public partial class _Default : System.Web.UI.Page

{

#region Declaration

string eMailId;

#endregion

protected void Page_Load(object sender, EventArgs e)

{

}

protected void Button1_Click(object sender, EventArgs e)

{

eMailId = bhala.n@insoft.com;

MailMessage ObjMail = new MailMessage();

ObjMail.To = txtTofield.Text;

ObjMail.Cc = TextBox1.Text;

ObjMail.Bcc = TextBox2.Text;

ObjMail.From = eMailId.ToString();

ObjMail.Body = txtTextArea.Text.ToString();

ObjMail.BodyFormat = MailFormat.Html;

SmtpMail.SmtpServer = System.Configuration.ConfigurationSettings.AppSettings["SMTPServer"].ToString();

SmtpMail.Send(ObjMail);

Response.Write(“The Mail has been sent to: “);

Response.Write(ObjMail.To);

Response.Write(ObjMail.Cc);

Response.Write(ObjMail.Bcc);

}

}

}

Html

<%@ Page Language=”C#” AutoEventWireup=”true” CodeBehind=”Default.aspx.cs” Inherits=”emailexample._Default” %>

<!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>Untitled Page</title>

</head>

<body>

<form id=”form1″ runat=”server”>

<div>

<table border =”2″ >

<tr>

<td>

<%– <asp:TextBox ID=”txtTofield” runat=”server” Text=”bhala.n@insoft.com” ReadOnly=”true”></asp:TextBox>–%>

<asp:Label ID=”lblTo” runat =”server” >To</asp:Label>

</td>

<td>

<asp:TextBox ID=”txtTofield” runat=”server” ></asp:TextBox>

</td>

</tr>

<tr>

<td>

<asp:Label ID=”Label1″ runat =”server” >Cc</asp:Label>

</td>

<td>

<asp:TextBox ID=”TextBox1″ runat=”server” ></asp:TextBox>

</td>

</tr>

<tr>

<td>

<%– <asp:TextBox ID=”txtTofield” runat=”server” Text=”bhuvanvel@gmail.com” ReadOnly=”true”></asp:TextBox>–%>

<asp:Label ID=”Label2″ runat =”server” >Bcc</asp:Label>

</td>

<td>

<asp:TextBox ID=”TextBox2″ runat=”server” ></asp:TextBox>

</td>

</tr>

<tr>

<td>

<asp:TextBox ID=”txtTextArea” runat=”server” TextMode=”MultiLine” Height=”175px”

Width=”600px”></asp:TextBox>

</td>

</tr>

<tr>

<td>

<asp:Button ID=”Button1″ runat=”server”

Text=”Send” OnClick=”Button1_Click” />

</td>

</tr>

</table>

</div>

</form>

</body>

</html>

Webconfig

<appSettings>

<add key=SMTPServer value=mail.google.com></add>

<add key=From value=noreply@words-online.com></add>

</appSettings>

Leave a response

Your response:

Categories