Best Projects

Bug Trackingsystem,Books online shopping,college management system,HR management system,Internet banking,Online chat room ,Online exam,Telephone billing system,Banking application,ATM database,airways reservation system,virtual network computing ,calculator,SMTP(simple mail transfer protocol)

Smart Mail(Big project)

//Index





Login





SMART-Mail














Username:
Password:

             





                            New User Sign-up

                               Forgot Password???











//Compose

compose



SMART-Mail








Inbox
Compose
Options
Sign Out



















To
Subject
Compose
















//Fpass

forgot password




SMART-Mail













Enter your userid :











//New User Form


New User Registration




SMART-Mail








New User Form





*User-id: @SMART-Mail.com


*Password:


*Re-Enter Password:


*Secret Question:


*Answer:
















Personal Details



*Name:




*Birth Date: (MM/DD/YYYY)

*User add:


*Gender: M F











//Password


Changing Password






SMART-Mail








Change Password




Old Password :
New Password :
Re-Enter New Password :








//INBOX DELETE

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import SMARTMAIL.*;



public class InboxDelete extends HttpServlet
{
public void service(HttpServletRequest rq,HttpServletResponse rs) throws IOException,ServletException
{
PrintWriter out=rs.getWriter();
rs.setContentType("text/html");
Connection con=null;
try
{
HttpSession obj=null;
obj=rq.getSession(true);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:mail");
Statement s=con.createStatement();

//Validate Session
File check=new File("c:/java/userinfo.txt");
if(!check.isFile())
{
HeaderPrint.Invalid(rq,rs);
}

// Get user name
FileReader fr=new FileReader("c:/java/userinfo.txt");
BufferedReader br=new BufferedReader(fr);
String usernam="";
String temp;
while((temp=br.readLine())!=null)
{
usernam=usernam+temp;
}
fr.close();

HeaderPrint.InboxMsg(rq,rs,usernam,2); //display html page

int i=0,count=0;
String uid[] = new String [32];
String t[] = new String [32];

// Copy Selected checkboxes into uid[]
while(i<30)
{
i++;
t[i] = rq.getParameter(""+i+""); //get the Unique mail id
if(t[i] != null)
{
uid[count] =t[i];
System.out.println("Value of uid["+count+"]:"+uid[count]);
count++;
}
}
System.out.println("Count:"+count);

if(count==0)
{

out.println("
");
out.println("
");
out.println("

No Messages Selected

");
out.println("
");
}
else
{
i=0;
String id;
do
{
id = uid[i];
String query="select * from inbox where receiver='"+usernam+"' and id='"+id+"'";
ResultSet rt=s.executeQuery(query);
if(rt.next())
{
String query2="delete from inbox where id='"+id+"'";
s.executeUpdate(query2);
}
i++;
}while(i if(count == 1)
out.println("
Message deleted!
");
else
out.println("
"+count+" Messages deleted!
");
}

}
catch(Exception e)
{
System.out.println(e);
}
finally
{
out.close();
}
}
}




//Inbox Display
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import SMARTMAIL.*;


public class InboxDisplay extends HttpServlet
{

public void service(HttpServletRequest rq,HttpServletResponse rs) throws IOException,ServletException
{
PrintWriter out=rs.getWriter();
rs.setContentType("text/html");
Connection con=null;
try
{
HttpSession obj=null;
obj=rq.getSession(true);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:mail");
Statement s=con.createStatement();
File check=new File("c:/java/userinfo.txt");
if(!check.isFile())
{
HeaderPrint.Invalid(rq,rs);
}

FileReader fr=new FileReader("c:/java/userinfo.txt");
BufferedReader br=new BufferedReader(fr);
String usernam="";
String temp;
while((temp=br.readLine())!=null)
{
usernam=usernam+temp;
}
fr.close();

//display html page
HeaderPrint.InboxMsg(rq,rs,usernam,2);

String query="select * from inbox where receiver='"+usernam+"' order by Flag,sdate DESC";
ResultSet rt=s.executeQuery(query);
if(rt.next())
{
ResultSet result = s.executeQuery(query);
out.println("
");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");

int sno = 1;
int number = 1; // variable to count the number of checkboxes
while(result.next())
{
String sen=result.getString("sender");
String sub=result.getString("subj");
String s_date=result.getString("sdate");
String msg=result.getString("mess");
String uid=result.getString("id");
String flg=result.getString("Flag");
out.println("");
String m="0";
if(flg.equals(m))
out.println("");
else
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");
number++;
sno++;
}
out.println("
No.FlagFromDateSubject
"+sno+"N
"+sno+"R"+sen+""+s_date+""+sub+"
");
out.println("

");


out.println("

");
out.println("

");

}
else
{
out.println("
");
out.println("
");
out.println("

No Messages

");
out.println("
");
}

}
catch(Exception e)
{
System.out.println(e);
}
finally
{
out.close();
}
}
}



//Inbox Read

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import SMARTMAIL.*;



public class InboxRead extends HttpServlet
{
public void service(HttpServletRequest rq,HttpServletResponse rs) throws IOException,ServletException
{
PrintWriter out=rs.getWriter();
rs.setContentType("text/html");
Connection con=null;
try
{
HttpSession obj=null;
obj=rq.getSession(true);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:mail");
Statement s=con.createStatement();
File check=new File("c:/java/userinfo.txt");
if(!check.isFile())
{
HeaderPrint.Invalid(rq,rs);
}

FileReader fr=new FileReader("c:/java/userinfo.txt");
BufferedReader br=new BufferedReader(fr);
String usernam="";
String temp;
while((temp=br.readLine())!=null)
{
usernam=usernam+temp;
}
fr.close();

//display html page
HeaderPrint.InboxMsg(rq,rs,usernam,2);

//Get the Uinique mail id
String uid = rq.getParameter("UID");
String query="select * from inbox where receiver='"+usernam+"' and id='"+uid+"'";
ResultSet rt=s.executeQuery(query);
if(rt.next())
{

String sen=rt.getString("sender");
String sub=rt.getString("subj");
String s_date=rt.getString("sdate");
String msg=rt.getString("mess");
out.println("
");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("
From:"+sen+"
Subject:"+sub+"
Date:"+s_date+"
Message
");
out.println("
REPLY");
out.println("  Forward
");

String queryup="update inbox set flag=1 where id ='"+rt.getString("id")+"'";
s.executeQuery(queryup);
}

}
catch(Exception e)
{
System.out.println(e);
}
finally
{
out.close();
}
}
}




// DEBUGGING INFO
//current
31/07/2004

modified reply some problem with headerPrint writer

01/08/2004

reply working. no bugs found

01/08/2004 1:30:00 PM

working on linking subject to the message in the inbox.





//Errors
Errors:
--------------------------------
1. Check the date validation in newuser.html onvalidate() fuction [done]

2. DoB year must be less than current year [Done]

3. sort the msgs in inbox according to date [Done]

4. Modify Getdate class [DONE]

5. Modify the Reply option. [Done]

6. Check the "Gender" radio type in new user form [Done]

7. include time field in the GetDate class [done]




//Formatting
1. reply


//Things to do
1. Include file system
2. display size field in inbox
3. Validation for password (should not be less than 4charcters and less then 10 charcters) [DONE]
4. Link subject directly to the message.Remove the radio selection option. [done]
5. Reply. [Done]
6. Forward. [done]




//GETDATA
package SMARTMAIL;

import java.util.Calendar;

public class GetDate
{
public static String Today( )
{
Calendar cal =Calendar.getInstance();
String date = " "+(cal.get(Calendar.MONTH)+1)+"/"+(cal.get(Calendar.DATE)) +"/"+(cal.get(Calendar.YEAR));
String time =" "+(cal.get(Calendar.HOUR))+":"+(cal.get(Calendar.MINUTE))+":"+(cal.get(Calendar.SECOND));
/* Check if the Time is AM or PM
* AM = 0 PM =1
*/
int am_pm =(cal.get(Calendar.AM_PM));
if(am_pm == 0)
time = time + " AM";
else
time = time + " PM";

date = date + time;
System.out.print(" "+date+" ");
return date;
}
}







//HeaderPrint
package SMARTMAIL;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HeaderPrint extends HttpServlet
{
public static void Invalid(HttpServletRequest rq,HttpServletResponse res)
throws IOException,ServletException
{
PrintWriter out=res.getWriter();
out.print("

SMART-Mail

");
out.print("");
out.println("
");
out.println("



Your Session expired Please Re-Login
");
out.println("


");
out.println("
Return to login Page
");
}
public static void Home(HttpServletRequest rq,HttpServletResponse res)
throws IOException,ServletException
{
PrintWriter out=res.getWriter();
out.print("

SMART-Mail

");
out.print("
");
out.println("
");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("
InboxComposeOptionsSign-out");
out.println("


");
}

public static void Head(HttpServletRequest rq,HttpServletResponse res)
throws IOException,ServletException
{
PrintWriter out=res.getWriter();
//display the Html header
out.print("

SMART-Mail

");
out.print("
");
out.println("
");
}

public static void InboxMsg(HttpServletRequest rq,HttpServletResponse res,String usernam,int i)
throws IOException,ServletException
{
PrintWriter out=res.getWriter();
out.print("

SMART-Mail

");
out.print("");
if(i==1)
{
out.print("

Welcome "+usernam+"

");
}else if(i==2)
{
out.println("

Inbox for "+usernam+"

");
}

out.println("
");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("
InboxComposeOptionsSign-out");
out.println("
");
}
public static void InvalidUser(HttpServletRequest rq,HttpServletResponse res)
throws IOException,ServletException
{
PrintWriter out=res.getWriter();
HeaderPrint.Head(rq,res);
out.println("
INVALID USER
");
out.println("
Return to login Page
");

}
public static void Logout(HttpServletRequest rq,HttpServletResponse res,String usernam)
throws IOException,ServletException
{
PrintWriter out=res.getWriter();
HeaderPrint.Head(rq,res);
out.print("

Thank you "+usernam+"

");
out.println("



");
out.println("

Thank you for using SMART-Mail

you have logged out successfully

");
out.println("
Login New User
");

}
}





//MultiUsers

package SMARTMAIL;
import java.util.*;

public class Multiusers
{
public static String[] Split(String toSend)
{
String send[]=new String[10];
int count=0,index=0;

for(int i=0;i<10;i++)
{
send[i]=null;
}

while(index !=-1)
{
index=toSend.indexOf(',');
if(index !=-1)
{
send[++count]=toSend.substring(0,index);
System.out.println("Send["+count+"]:"+send[count]);
toSend=toSend.substring(index+1);

}

}
send[++count]=toSend;
System.out.println("send["+count+"]:"+send[count]);

return send;

}
}





//Uniquield

package SMARTMAIL;

import java.util.*;


public class Uniqueid
{
public static String generate(int i)
{

Date date =new Date();
long msec =date.getTime();
Random r=new Random(msec+(1000*i));
int l = (int) (100*r.nextDouble());
int n =(int) (100*r.nextDouble());
Random s=new Random(msec-(1000*i));
int d =(int) (100*s.nextDouble());
char[] ch={((char) (65+(n%26))),((char) (65+(d%26))),((char) (65+(l%26)))};
String uniqid= new String(ch);
uniqid =uniqid+n+d+l;
System.out.print("Unique-id: "+uniqid);
return uniqid;
}
}






//Compose
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.*;
import SMARTMAIL.*;


public class compose extends HttpServlet
{
public void service(HttpServletRequest rq,HttpServletResponse res)
throws IOException,ServletException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();

try
{
HttpSession obj=null;
obj=rq.getSession(true);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:mail");
Statement st=conn.createStatement();
File check=new File("c:/java/userinfo.txt");
if(!check.isFile())
{
HeaderPrint.Invalid(rq,res);
}
FileReader fr=new FileReader("c:/java/userinfo.txt");
BufferedReader br=new BufferedReader(fr);
String usernam="";
String temp;
while((temp=br.readLine())!=null)
{
usernam=usernam+temp;
}
fr.close();
String toSend=rq.getParameter("receiver");
String sub=rq.getParameter("comp1");
String msg=rq.getParameter("comp");


// Sending to multiple user's
System.out.println("String:"+toSend);
String send[]=new String[10];

/* Split the string and store the individual addresses in the array */
send =Multiusers.Split(toSend);


//Display the html page
HeaderPrint.Home(rq,res);
int i=1; // count variable
while(send[i] != null)
{
String receiver1 = send[i];
String q="select userid from userinfo where userid='"+receiver1+"'";
ResultSet r1=st.executeQuery(q);
if(r1.next())
{
/* assign Unique id for each mail to be send */
String uniqid = Uniqueid.generate(i);
String date =GetDate.Today();

//testing
System.out.println("Sending to receiver["+i+ "]:"+receiver1);

/* Entering data into the database */
st.executeUpdate("insert into inbox(receiver,sender,subj,sdate,mess,id,Flag)values('"+receiver1+"','"+usernam+"','"+sub+"','"+date+"','"+msg+"','"+uniqid+"','0')");
conn.commit();
out.println("

Your Message has been sent succesfully to "+send[i]+"@SMART-mail.com

");
}
else
{

out.println("

Your Message cannot be send since "+send[i]+"@SMART-mail.com does not exists

");

}//if(r1.next())
i++; // incrementing the count variable

}//while(i!=count)

}
catch(Exception e)
{
System.out.println("Not valid"+e.getMessage());
}
}
}




//First page
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.*;
import SMARTMAIL.*;

public class FirstPage extends HttpServlet
{
public void service(HttpServletRequest rq,HttpServletResponse res)
throws IOException,ServletException
{
PrintWriter out=null;
res.setContentType("text/html");
HttpSession obj=null;
obj=rq.getSession(true);
try
{

out=res.getWriter();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:mail");
Statement st=conn.createStatement();
String name=rq.getParameter("userid");
String pass=rq.getParameter("passwd");
ResultSet rs=st.executeQuery("Select userid,passwd from userinfo where userid='"+name+" '"+"and passwd='"+pass+" '");
FileWriter f1=new FileWriter("c:/java/userinfo.txt");
f1.write(name);
f1.close();

if(rs.next())
{
res.sendRedirect("http://127.0.0.1:8080/examples/servlet/Inbox");
}
else
{

HeaderPrint.InvalidUser(rq,res);

}
}
catch(Exception f)
{
System.out.println(f.getMessage());
}
}
}





//Forward
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import SMARTMAIL.*;

public class Forward extends HttpServlet
{
public void service(HttpServletRequest rq,HttpServletResponse rs) throws IOException,ServletException
{
PrintWriter out=rs.getWriter();
rs.setContentType("text/html");
Connection con=null;
try
{
HttpSession obj=null;
obj=rq.getSession(true);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:mail");
Statement s=con.createStatement();

//Check if Session is valid
File check=new File("c:/java/userinfo.txt");
if(!check.isFile())
{
HeaderPrint.Invalid(rq,rs);
}

//Get the username and email_id
FileReader fr=new FileReader("c:/java/userinfo.txt");
BufferedReader br=new BufferedReader(fr);
String usernam="";
String temp;
while((temp=br.readLine())!=null)
{
usernam=usernam+temp;
}
fr.close();
String uid = rq.getParameter("UID");

//Get the Sender's name,subject and message from the mailbox
String query="select * from inbox where receiver='"+usernam+"' and id='"+uid+"'";
ResultSet rt=s.executeQuery(query);
if(rt.next())
{
String sen = rt.getString("sender");
String sub = rt.getString("subj");
String msg = rt.getString("mess");
String date = rt.getString("sdate");
String message ="\n\nNOTE:Forwarded message below.\n";
message +="Original Message:\nFrom:"+sen+"\nTo:"+usernam+"\nOn:"+date;
message +="\n---------------------------------\n"+msg;


//Display html page
HeaderPrint.Home(rq,rs);
out.println("
");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("
To:
Subject:
Message :
");
out.println("");
out.println("
");
}

}

catch(Exception e)
{
System.out.println(e);
}
finally
{
out.close();
}
}
}





//Fpass
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import SMARTMAIL.*;


public class fpass extends HttpServlet
{
public void service(HttpServletRequest rq,HttpServletResponse rs) throws IOException,ServletException
{
PrintWriter out=rs.getWriter();
rs.setContentType("text/html");
Connection con=null;
try
{
HttpSession obj=null;
obj=rq.getSession(true);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:mail");
Statement st=con.createStatement();
String uid = rq.getParameter("userid");
String q="select * from userinfo where userid='"+uid+"'";
ResultSet r1=st.executeQuery(q);

//display the Html header
HeaderPrint.Head(rq,rs);

if(r1.next())
{
String quest=r1.getString("quest");
FileWriter f1=new FileWriter("c:/java/user.txt");
f1.write(uid);
f1.close();

out.println("
");
out.println("

");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("
Your Question:"+quest+"
Answer:
");
out.println("
");
}
else
{

out.println("
");
out.println(" Userid does not Exist ");
out.println("please try again


");
out.println("
");
}
}
catch(Exception e)
{
System.out.println(e);
}
finally
{
out.close();
}
}
}



//Inbox

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import SMARTMAIL.*;


public class Inbox extends HttpServlet
{

public void service(HttpServletRequest rq,HttpServletResponse rs) throws IOException,ServletException
{
PrintWriter out=rs.getWriter();
rs.setContentType("text/html");
Connection con=null;
try
{
HttpSession obj=null;
obj=rq.getSession(true);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:mail");
Statement s=con.createStatement();
File check=new File("c:/java/userinfo.txt");
if(!check.isFile())
{
HeaderPrint.Invalid(rq,rs);
}
FileReader fr=new FileReader("c:/java/userinfo.txt");
BufferedReader br=new BufferedReader(fr);
String usernam="";
String temp;
while((temp=br.readLine())!=null)
{
usernam=usernam+temp;
}
fr.close();
HeaderPrint.InboxMsg(rq,rs,usernam,1);

String query="select * from inbox where receiver='"+usernam+"' and Flag='0'";
ResultSet rt=s.executeQuery(query);
if(rt.next())
{
int n =1;
while(rt.next())
{
n++;
}
out.println("



You got "+n+" New Messages

");

}
else
{
out.println("
");
out.println("
");
out.println("

No New Messages

");
out.println("
");
}

}
catch(Exception e)
{
System.out.println(e);
}
finally
{
out.close();
}
}
}







//Inbox delete

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import SMARTMAIL.*;



public class InboxDelete extends HttpServlet
{
public void service(HttpServletRequest rq,HttpServletResponse rs) throws IOException,ServletException
{
PrintWriter out=rs.getWriter();
rs.setContentType("text/html");
Connection con=null;
try
{
HttpSession obj=null;
obj=rq.getSession(true);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:mail");
Statement s=con.createStatement();

//Validate Session
File check=new File("c:/java/userinfo.txt");
if(!check.isFile())
{
HeaderPrint.Invalid(rq,rs);
}

// Get user name
FileReader fr=new FileReader("c:/java/userinfo.txt");
BufferedReader br=new BufferedReader(fr);
String usernam="";
String temp;
while((temp=br.readLine())!=null)
{
usernam=usernam+temp;
}
fr.close();

HeaderPrint.InboxMsg(rq,rs,usernam,2); //display html page

int i=0,count=0;
String uid[] = new String [32];
String t[] = new String [32];

// Copy Selected checkboxes into uid[]
while(i<30)
{
i++;
t[i] = rq.getParameter(""+i+""); //get the Unique mail id
if(t[i] != null)
{
uid[count] =t[i];
System.out.println("Value of uid["+count+"]:"+uid[count]);
count++;
}
}
System.out.println("Count:"+count);

if(count==0)
{

out.println("
");
out.println("
");
out.println("

No Messages Selected

");
out.println("
");
}
else
{
i=0;
String id;
do
{
id = uid[i];
String query="select * from inbox where receiver='"+usernam+"' and id='"+id+"'";
ResultSet rt=s.executeQuery(query);
if(rt.next())
{
String query2="delete from inbox where id='"+id+"'";
s.executeUpdate(query2);
}
i++;
}while(i if(count == 1)
out.println("
Message deleted!
");
else
out.println("
"+count+" Messages deleted!
");
}

}
catch(Exception e)
{
System.out.println(e);
}
finally
{
out.close();
}
}
}







//Inbox display
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import SMARTMAIL.*;


public class InboxDisplay extends HttpServlet
{

public void service(HttpServletRequest rq,HttpServletResponse rs) throws IOException,ServletException
{
PrintWriter out=rs.getWriter();
rs.setContentType("text/html");
Connection con=null;
try
{
HttpSession obj=null;
obj=rq.getSession(true);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:mail");
Statement s=con.createStatement();
File check=new File("c:/java/userinfo.txt");
if(!check.isFile())
{
HeaderPrint.Invalid(rq,rs);
}

FileReader fr=new FileReader("c:/java/userinfo.txt");
BufferedReader br=new BufferedReader(fr);
String usernam="";
String temp;
while((temp=br.readLine())!=null)
{
usernam=usernam+temp;
}
fr.close();

//display html page
HeaderPrint.InboxMsg(rq,rs,usernam,2);

String query="select * from inbox where receiver='"+usernam+"' order by Flag,sdate DESC";
ResultSet rt=s.executeQuery(query);
if(rt.next())
{
ResultSet result = s.executeQuery(query);
out.println("
");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");

int sno = 1;
int number = 1; // variable to count the number of checkboxes
while(result.next())
{
String sen=result.getString("sender");
String sub=result.getString("subj");
String s_date=result.getString("sdate");
String msg=result.getString("mess");
String uid=result.getString("id");
String flg=result.getString("Flag");
out.println("");
String m="0";
if(flg.equals(m))
out.println("");
else
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");
number++;
sno++;
}
out.println("
No.FlagFromDateSubject
"+sno+"N
"+sno+"R"+sen+""+s_date+""+sub+"
");
out.println("

");


out.println("

");
out.println("

");

}
else
{
out.println("
");
out.println("
");
out.println("

No Messages

");
out.println("
");
}

}
catch(Exception e)
{
System.out.println(e);
}
finally
{
out.close();
}
}
}







//Inbox Read

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import SMARTMAIL.*;



public class InboxRead extends HttpServlet
{
public void service(HttpServletRequest rq,HttpServletResponse rs) throws IOException,ServletException
{
PrintWriter out=rs.getWriter();
rs.setContentType("text/html");
Connection con=null;
try
{
HttpSession obj=null;
obj=rq.getSession(true);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:mail");
Statement s=con.createStatement();
File check=new File("c:/java/userinfo.txt");
if(!check.isFile())
{
HeaderPrint.Invalid(rq,rs);
}

FileReader fr=new FileReader("c:/java/userinfo.txt");
BufferedReader br=new BufferedReader(fr);
String usernam="";
String temp;
while((temp=br.readLine())!=null)
{
usernam=usernam+temp;
}
fr.close();

//display html page
HeaderPrint.InboxMsg(rq,rs,usernam,2);

//Get the Uinique mail id
String uid = rq.getParameter("UID");
String query="select * from inbox where receiver='"+usernam+"' and id='"+uid+"'";
ResultSet rt=s.executeQuery(query);
if(rt.next())
{

String sen=rt.getString("sender");
String sub=rt.getString("subj");
String s_date=rt.getString("sdate");
String msg=rt.getString("mess");
out.println("
");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("
From:"+sen+"
Subject:"+sub+"
Date:"+s_date+"
Message
");
out.println("
REPLY");
out.println("  Forward
");

String queryup="update inbox set flag=1 where id ='"+rt.getString("id")+"'";
s.executeQuery(queryup);
}

}
catch(Exception e)
{
System.out.println(e);
}
finally
{
out.close();
}
}
}







//Logout
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import SMARTMAIL.*;


public class Logout extends HttpServlet
{
public void service(HttpServletRequest rq,HttpServletResponse res)
throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
Connection con=null;
try
{
HttpSession obj=null;
obj=rq.getSession(true);
File check=new File("c:/java/userinfo.txt");
if(!check.isFile())
{
HeaderPrint.Invalid(rq,res);
}
FileReader userinfo=new FileReader("c:/java/userinfo.txt");
BufferedReader br=new BufferedReader(userinfo);
String usernam="";
String temp;
while((temp=br.readLine())!=null)
{
usernam=usernam+temp;
}
userinfo.close();

// Delete the temp files
File temp1=new File("c:/java/userinfo.txt");
File temp2=new File("c:/java/uid.txt");
temp1.delete();
temp2.delete();

// Display the Logout Page
HeaderPrint.Logout(rq,res,usernam);

} // end of try block
catch(Exception e)
{
System.out.println("Invalid"+e.getMessage());
}
}
}




//Newuser
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.*;
import SMARTMAIL.*;

public class newuser extends HttpServlet
{
public void service(HttpServletRequest rq,HttpServletResponse res)
throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
try
{
HttpSession obj=null;
obj=rq.getSession(true);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:mail");
Statement st=conn.createStatement();
String user=rq.getParameter("userid");
String pass=rq.getParameter("passwd");
String repass=rq.getParameter("repasswd");
String fname=rq.getParameter("username");
String question=rq.getParameter("quest");
String answer=rq.getParameter("ans");
String useradd=rq.getParameter("useradd");
String mm=rq.getParameter("mm");
String dd=rq.getParameter("dd");
String yy=rq.getParameter("yy");
String Bdate= mm + "/" +dd+"/"+yy;
String sex=rq.getParameter("sex");



HeaderPrint.Head(rq,res);

if(user.equals("")||pass.equals("")||repass.equals("")||fname.equals("")||useradd.equals("")||Bdate.equals(""))
{

out.println("

one of the fields is empty

");
out.println("
");
out.println("
");
out.println("
");

}

FileWriter f1=new FileWriter("c:/java/userinfo.txt");
f1.write(user);
f1.close();
ResultSet rs=st.executeQuery("SELECT userid FROM userinfo where userid='"+user+"'");
if(rs.next())
{

out.println("

user id "+user+" already exists

");
out.println("
try another id
");
out.println("
");
out.println("
");
out.println("
");
}
else
{
if(pass.equals(repass))
{
st.executeUpdate("insert into userinfo(userid,passwd,username,useradd,quest,ans,dob,gender)values('"+user+"','"+pass+"','"+fname+"','"+useradd+"','"+question+"','"+answer+"','"+Bdate+"','"+sex+"')");
conn.commit();
out.println("

Welcome "+user+"");
out.println("

You have been Registered successfully at Bunnymail
");
out.println("


");
out.println("
");
out.println("
");
out.println("
");
}
else
{
out.println("

Typed passwords do not match

");
out.println("
");
out.println("
");
out.println("
");
}
}
}
catch(Exception e)
{
System.out.println("Not valid"+e.getMessage());
}
}
}



//password
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import SMARTMAIL.*;

public class password extends HttpServlet
{
public void service(HttpServletRequest rq,HttpServletResponse res)
throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
String name1= rq.getRemoteUser();
Connection con=null;
try
{
HttpSession obj=null;
obj=rq.getSession(true);
File check=new File("c:/java/userinfo.txt");
if(!check.isFile())
{
HeaderPrint.Invalid(rq,res);
}

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:mail");
Statement st=conn.createStatement();

FileReader userinfo=new FileReader("c:/java/userinfo.txt");
BufferedReader br=new BufferedReader(userinfo);
String name="";
String temp;
while((temp=br.readLine())!=null)
{
name=name+temp;
}
String pass=rq.getParameter("oldpasswd");
String newpass=rq.getParameter("newpasswd");
String newpass1=rq.getParameter("newpasswd1");
userinfo.close();
//Display html page
HeaderPrint.Home(rq,res);
ResultSet rs=st.executeQuery("Select userid,passwd from userinfo where userid='"+name+" '"+"and passwd='"+pass+" '");

if(rs.next())
{
st.executeUpdate("update userinfo set passwd='"+newpass+"'where userid='"+name+"' and passwd='"+pass+"'");
out.println("

Your password has been changed

");
}
else
{
out.println("

Invalid password

");
}
}
catch(Exception e)
{
System.out.println("Invalid"+e.getMessage());
}
}
}





//Reply
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import SMARTMAIL.*;

public class reply extends HttpServlet
{
public void service(HttpServletRequest rq,HttpServletResponse rs) throws IOException,ServletException
{
PrintWriter out=rs.getWriter();
rs.setContentType("text/html");
Connection con=null;
try
{
HttpSession obj=null;
obj=rq.getSession(true);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:mail");
Statement s=con.createStatement();

//Check if Session is valid
File check=new File("c:/java/userinfo.txt");
if(!check.isFile())
{
HeaderPrint.Invalid(rq,rs);
}

//Get the username and email_id
FileReader fr=new FileReader("c:/java/userinfo.txt");
BufferedReader br=new BufferedReader(fr);
String usernam="";
String temp;
while((temp=br.readLine())!=null)
{
usernam=usernam+temp;
}
fr.close();
String uid = rq.getParameter("UID");

//Get the Sender's name,subject and message from the mailbox
String query="select * from inbox where receiver='"+usernam+"' and id='"+uid+"'";
ResultSet rt=s.executeQuery(query);
if(rt.next())
{
String sen = rt.getString("sender");
String sub = rt.getString("subj");
String msg = rt.getString("mess");
String date = rt.getString("sdate");
String message = " \""+sen+" wrote on "+date+"\"\n "+msg;


//Display html page
HeaderPrint.Home(rq,rs);
out.println("
");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("
To:
Subject:
Message :
");
out.println("");
out.println("
");
}

}

catch(Exception e)
{
System.out.println(e);
}
finally
{
out.close();
}
}
}







//import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import SMARTMAIL.*;

public class vpass extends HttpServlet
{
public void service(HttpServletRequest rq,HttpServletResponse rs) throws IOException,ServletException
{
PrintWriter out=rs.getWriter();
rs.setContentType("text/html");
Connection con=null;
try
{
HttpSession obj=null;
obj=rq.getSession(true);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:mail");
Statement st=con.createStatement();
FileReader fr=new FileReader("c:/java/user.txt");
BufferedReader br=new BufferedReader(fr);
String usernam="";
String temp;
while((temp=br.readLine())!=null)
{
usernam=usernam+temp;
}
fr.close();
String ans = rq.getParameter("ans");
String q="select passwd from userinfo where userid='"+usernam+"' and ans='"+ans+"'";
ResultSet r1=st.executeQuery(q);
if(r1.next())
{
String passwd=r1.getString("passwd");

//display head
HeaderPrint.Head(rq,rs);
out.println("
");
out.println("
");
out.println("

Your Password is:"+passwd+"");
out.println("

");
out.println("
");

out.println("
");
}
else
{
out.print("

Bunny Mail

");
out.print("
");
out.println("
");

out.println("
");
out.println("

The answer does not match,try again");

out.println("

");
}
}
catch(Exception e)
{
System.out.println(e);
}
finally
{
out.close();
}
}
}







//Vpass
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import SMARTMAIL.*;

public class vpass extends HttpServlet
{
public void service(HttpServletRequest rq,HttpServletResponse rs) throws IOException,ServletException
{
PrintWriter out=rs.getWriter();
rs.setContentType("text/html");
Connection con=null;
try
{
HttpSession obj=null;
obj=rq.getSession(true);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:mail");
Statement st=con.createStatement();
FileReader fr=new FileReader("c:/java/user.txt");
BufferedReader br=new BufferedReader(fr);
String usernam="";
String temp;
while((temp=br.readLine())!=null)
{
usernam=usernam+temp;
}
fr.close();
String ans = rq.getParameter("ans");
String q="select passwd from userinfo where userid='"+usernam+"' and ans='"+ans+"'";
ResultSet r1=st.executeQuery(q);
if(r1.next())
{
String passwd=r1.getString("passwd");

//display head
HeaderPrint.Head(rq,rs);
out.println("
");
out.println("");
out.println("

Your Password is:"+passwd+"");
out.println("

");
out.println("");

out.println("
");
}
else
{
out.print("

Bunny Mail

");
out.print("
");
out.println("
");

out.println("
");
out.println("

The answer does not match,try again");

out.println("

");
}
}
catch(Exception e)
{
System.out.println(e);
}
finally
{
out.close();
}
}
}

































No comments: