C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » C# Syntax »

Mail Notification


Posted Date: 06 Jul 2007    Resource Type: Code Snippets    Category: C# Syntax
Author: Prachi JoshiMember Level: Bronze    
Rating: 1 out of 5Points: 10



This code provides a mail notification facility



HTML
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="MailNotify.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Button id="btnSend" style="Z-INDEX: 101; LEFT: 213px; POSITION: absolute; TOP: 134px" runat="server"
Text="Send Mail"></asp:Button>
</form>
</body>
</HTML>




CODE BEHIND

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Mail;
using System.Net;
using System.IO;
using System.Text;

namespace MailNotify
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnSend;



private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here


}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnSend.Click += new System.EventHandler(this.btnSend_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void btnSend_Click(object sender, System.EventArgs e)
{
string strRequestorFor="Prachi G Joshi";
string strReuestedBy="Prachi S Joshi";


DataTable dt= new DataTable();

dt.Columns.Add("Workshop_Name");
dt.Columns.Add("Orientation_Date");
dt.Columns.Add("Swap_Value");
dt.Columns.Add("Swap_Name");
dt.Columns.Add("Swap_date");

DataRow dr= dt.NewRow();
dr["Workshop_Name"]="ABC";
dr["Orientation_Date"]="Dadar";
dr["Swap_Value"]="1/1/07";
dr["Swap_Name"]="Worli";
dr["Swap_date"]="7/7/07";
dt.Rows.Add(dr);

dr= dt.NewRow();
dr["Workshop_Name"]="DEF";
dr["Orientation_Date"]="Matunga";
dr["Swap_Value"]="2/1/07";
dr["Swap_Name"]="Kharghar";
dr["Swap_date"]="2/7/07";
dt.Rows.Add(dr);

MailNotify(strRequestorFor,strReuestedBy,dt);

}

public void MailNotify(string strRequestorFor,string strReuestedBy,DataTable dt)
{


// create mail message object
MailMessage mail = new MailMessage();
mail.From = "prachi.joshi@siemens.com"; // put the from address here
mail.To = "prachi.joshi@siemens.com"; // put to address here
mail.Subject = "Request For Swap"; // put subject here


string strMsgStart = "<html><head><style type='text/css'>.tdclass { FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana; TEXT-ALIGN: center; BACKGROUND-COLOR: 'Gainsboro'; }.tableclass { TABLE-LAYOUT: auto; }.trclass { FONT-WEIGHT: bold; FONT-SIZE: 10pt; COLOR: white; FONT-FAMILY: Verdana; BACKGROUND-COLOR: '#000084'; TEXT-ALIGN: center }.bodyclass { FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana; TEXT-ALIGN: left }</style></head><body class='bodyclass'>" + "Dear" + " " + strRequestorFor + "," + "<br><br>The workshop requisition has been raised as shown below.<br><br>";
strMsgStart+= "Requested by: " + strReuestedBy + "<br>" + "Requested for Swap with: " + strRequestorFor ;
strMsgStart+= "<br><br><br><Table class='tableclass' border='1' cellspacing='0' cellpadding='0' bordercolor='#999999'><tr class='trclass'><td>Workshop Name</td><td>Requestor Venue</td><td>Requestor Workshop Date</td><td>Swapper Venue</td><td>Swapper Workshop Date</td></tr>";
string strMsgMiddle="";
for(int i=0;i<dt.Rows.Count;i++)
{
strMsgMiddle+="<tr>";

for (int j=0;j<dt.Columns.Count;j++)
{
string str=dt.Rows[i].ItemArray[j].ToString();
strMsgMiddle+="<td class='tdclass'>" + str + "</td>";
}

strMsgMiddle+="</tr>";
}

string strMsgEnd= "</Table><br><br>Please approve or reject the workshop swap requistion through URL <a href='http://localhost/MailNotify/WebForm1.aspx'>http://systemurl.co.in/gdpadmin</a><br><br>Regards,<br>GDP System</body></html>";
mail.BodyFormat = MailFormat.Html;
mail.Body = strMsgStart + strMsgMiddle + strMsgEnd; // put body of email here
SmtpMail.SmtpServer = System.Configuration.ConfigurationSettings.AppSettings["ExchangeIP"];; // put smtp server you will use here
// and then send the mail
SmtpMail.Send(mail);

}



}
}









Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Boxing
Previous Resource: How to validate a date using c#
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use