find at least ten pieces of spam mail from any account wheth
find at least ten pieces of spam mail from any account, whether it be home, work, school, or something else. using e-mail header and any website that might provide information attempt to trace the spam mail back to its original source.
you will need to following materials:
1. collect the e-mails and view the email header information into your program.
2. find the received field in the headers and write down as many DNS names or IP addresses as you can. also look for common details in the header element of the different messages, such as the same email servers and spammers.
Solution
 package com.spam;
import java.io.IOException;
 import java.io.PrintWriter;
 import javax.servlet.ServletException;
 import javax.servlet.annotation.WebServlet;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.util.Properties;
import javax.mail.Message;
 import javax.mail.MessagingException;
 import javax.mail.PasswordAuthentication;
 import javax.mail.Session;
 import javax.mail.Transport;
 import javax.mail.internet.InternetAddress;
 import javax.mail.internet.MimeMessage;
 import java.sql.*;
@WebServlet(name = \"SendMail\", urlPatterns = {\"/SendMail\"})
 public class SendMail extends HttpServlet {
@Override
 protected void doPost(HttpServletRequest request, HttpServletResponse response)
 throws ServletException, IOException {
 response.setContentType(\"text/html\");
 PrintWriter out = response.getWriter();
 String to = request.getParameter(\"to\");
 String subject = request.getParameter(\"subject\");
 String file = request.getParameter(\"file\");
 String msg = request.getParameter(\"msg\");
 final String username = \"USERMAIL ID\";
 final String password = \"geethaapsaraa/cdts\";
 try {
 Class.forName(\"com.mysql.jdbc.Driver\");
 Connection con = DriverManager.getConnection(\"jdbc:mysql://localhost:3306/spam\", \"root\", \"root\");
 Statement st = con.createStatement();
 int rs = st.executeUpdate(\"insert into emailsend(email,subject,file,msg) values(\'\" + to + \"\',\'\" + subject + \"\',\'\" + file + \"\',\'\" + msg + \"\')\");
 if (rs == 1) {
 System.out.println(\"data inserted\");
 } else {
 System.out.println(\"data not inserted\");
 }
 } catch (Exception e) {
 e.printStackTrace();
 }
Properties props = new Properties();
 props.put(\"mail.smtp.auth\", \"true\");
 props.put(\"mail.smtp.starttls.enable\", \"true\");
 props.put(\"mail.smtp.host\", \"SMTP ADDRESS\");
 props.put(\"mail.smtp.port\", \"587\");
Session session = Session.getInstance(props,
 new javax.mail.Authenticator() {
 protected PasswordAuthentication getPasswordAuthentication() {
 return new PasswordAuthentication(username, password);
 }
 });
try {
 Message message = new MimeMessage(session);
 message.setFrom(new InternetAddress(\"your email address\"));
 message.setRecipients(Message.RecipientType.TO,
 InternetAddress.parse(to));
 message.setSubject(subject);
 message.setText(msg);
Transport.send(message);
System.out.println(\"Done\");
 response.sendRedirect(\"mailsend.jsp\");
} catch (MessagingException e) {
 out.println(e);
 }
 }
 }
MailList.jsp
................
 <%@page contentType=\"text/html\" pageEncoding=\"UTF-8\"%>
 <%@ page import =\"java.sql.*\" %>
 <!DOCTYPE html>
 <html>
 <head>
 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
 <title>Mail List</title>
 <style type=\"text/css\">
 a
 {
 text-decoration: none;
 font-family: sans-serif;
 font-size: 18pt;
 font-style: normal;
 color: yellow;
 }
 a:hover
 {
 text-decoration: none;
 font-family: cursive;
 font-size: 19pt;
 font-style: italic;
 color: aqua;
 }
 body
 {
 background-color: #005CFF;
 color: white;
 font-size: 18pt;
 font-family: cursive;
 }
 </style>
 </head>
 <body>
   
 <table width=\"525\" border=\"1\">
 <tr>
 <td width=\"207\"><%
 String ip = request.getRemoteAddr();
 out.println(ip);   
 %></td>
 <td width=\"91\"><a href=\"mail_list.jsp\">Mail List</a></td>
 <td width=\"45\">Open</td>
 <td width=\"154\"><a href=\"filter.jsp\">Filter</a></td>
 </tr>
 </table>
   
 <%
 Class.forName(\"com.mysql.jdbc.Driver\");
 Connection con=DriverManager.getConnection(\"jdbc:mysql://localhost:3306/spam\",\"root\", \"root\");
 Statement st=con.createStatement();
 ResultSet rs=st.executeQuery(\"select email,subject from emailsend\");
 %>
   
 <table width=\"604\" border=\"1\">
 <tr>
 <td width=\"366\" height=\"254\"><table width=\"359\" border=\"1\">
 <tr>
 <td width=\"172\">To</td>
 <td width=\"171\">Mails</td>
 </tr>
 <%
 while(rs.next())
 {
 String email1=rs.getString(\"email\");
 //String file1=rs.getString(\"msg\");
 %>
 <tr>
 <td height=\"189\"><%=email1%></td>
 <%-- <td><%=file1%></td> --%>
 </tr>
 <%
 }
 %>
 </table>
 </td>
 <td width=\"222\"> </td>
 </tr>
 </table>
 </body>
 </html>
<%@page import =\"java.sql.*\" %>
 <%@page contentType=\"text/html\" pageEncoding=\"UTF-8\"%>
 <!DOCTYPE html>
 <html>
 <head>
 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
 <title>Calculating the Threshold</title>
 <style type=\"text/css\">
 a
 {
 text-decoration: none;
 font-family: sans-serif;
 font-size: 18pt;
 font-style: normal;
 color: yellow;
 }
 a:hover
 {
 text-decoration: none;
 font-family: cursive;
 font-size: 19pt;
 font-style: italic;
 color: aqua;
 }
 body
 {
 background-color: #005CFF;
 color: white;
 font-size: 18pt;
 font-family: cursive;
 }
 </style>
 </head>
 <body>
 <table align=\"center\" cellpadding=\"5\" cellspacing=\"5\">
 <%
 String sct = request.getParameter(\"ct\");
 String spt = request.getParameter(\"pt\");
 String ipaddress = \"\";
 if (!(sct.equals(\"\"))) {
 int ct = Integer.parseInt(sct);
 try {
 int spam_mail_count = 0;
 Class.forName(\"com.mysql.jdbc.Driver\");
 Connection conn = DriverManager.getConnection(\"jdbc:mysql://localhost:3306/spam\", \"root\", \"root\");
 PreparedStatement ps = conn.prepareStatement(\"select distinct ipaddress from slog\");
 ResultSet rs = ps.executeQuery();
while (rs.next()) {
 ipaddress = rs.getString(1);
 PreparedStatement pss = conn.prepareStatement(\"select spamcount from slog where ipaddress=?\");
 pss.setString(1, ipaddress);
 ResultSet rss = pss.executeQuery();
 while (rss.next()) {
 spam_mail_count += rss.getInt(1);
 }
}
 // out.print(\"spm count\" + spam_mail_count);
 if (spam_mail_count >= ct) {
 %>
 <tr><td>
 <%
 out.println(\"CT: \ System with \" + ipaddress + \" is compramised\");
 %>
 </td></tr>
 <%
 } else {
 %>
 <tr><td>
 <%
 out.println(\"No Compramise Machine Found\");
 %>
 </td></tr>
 <%}
} catch (Exception e) {
 out.println(\"Error: \" + e.getMessage());
 }
 } else {
int pt = Integer.parseInt(spt);
try {
 int spam_mail_count = 0;
 int tot_count = 0;
 Class.forName(\"com.mysql.jdbc.Driver\");
 Connection conn = DriverManager.getConnection(\"jdbc:mysql://localhost:3306/spam\", \"root\", \"root\");
 PreparedStatement ps = conn.prepareStatement(\"select distinct ipaddress from slog\");
 ResultSet rs = ps.executeQuery();
while (rs.next()) {
ipaddress = rs.getString(1);
PreparedStatement pstmt = conn.prepareStatement(\"select spamcount,nonspamcount from slog where ipaddress=?\");
 pstmt.setString(1, ipaddress);
 ResultSet rset = pstmt.executeQuery();
 while (rset.next()) {
 tot_count = tot_count+(rset.getInt(1) + rset.getInt(2));
 }
 PreparedStatement pss = conn.prepareStatement(\"select spamcount from slog where ipaddress=?\");
 pss.setString(1, ipaddress);
 ResultSet rss = pss.executeQuery();
 while (rss.next()) {
 spam_mail_count += rss.getInt(1);
 }
 }
 //out.println(\"Spam mail count: \" + spam_mail_count);
 //out.println(\"Total count: \" + tot_count);
 int calc_threshold = (spam_mail_count / tot_count) * 100;
 //out.print(\"calc Threshold: \" + calc_threshold);
 if (calc_threshold >= pt) {
 %>
 <tr><td>
 <%
 out.println(\"PT: \ System with \" + ipaddress + \" is compramised\");
 %>
 </td></tr>
 <%
 } else {
 %>
 <tr><td>
 <%
 out.println(\"No Compramise Machine Found\");
 %>
 </td></tr>
 <%}
} catch (Exception e) {
 out.println(\"Error: \" + e.getMessage());
 }
 }
 %>
 </table>
 </body>
 </html>
Filter.jsp
....................
<%@ page import =\"java.sql.*\" %>
 <%@page contentType=\"text/html\" pageEncoding=\"UTF-8\"%>
 <!DOCTYPE html>
 <html>
 <head>
 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
 <title>Filtering Messages</title>
 <style type=\"text/css\">
 a
 {
 text-decoration: none;
 font-family: sans-serif;
 font-size: 18pt;
 font-style: normal;
 color: yellow;
 }
 a:hover
 {
 text-decoration: none;
 font-family: cursive;
 font-size: 19pt;
 font-style: italic;
 color: aqua;
 }
 body
 {
 background-color: #005CFF;
 color: white;
 font-size: 18pt;
 font-family: cursive;
 }
 </style>
 </head>
 <body>
   
 <br>
 <br>
 <br>
 <form action=\"CalcThreshold.jsp\" method=\"post\">
 <table align=\"center\" cellpadding=\"5\" cellspacing=\"5\">
 <tr>
 <td>Count Threshold:</td>
 <td><input type=\"text\" size=\"3\" name=\"ct\"></td>
 <td><input type=\"submit\" value=\"Calculate\"></td>
 </tr>
 <tr>
 <td>Percentage Threshold:</td>
 <td><input type=\"text\" size=\"3\" name=\"pt\">%</td>
 <td><input type=\"submit\" value=\"Calculate\"></td>
 </tr>
 </table>
 </form>
 </body>
 </html>
<%@page import=\"java.util.StringTokenizer\"%>
 <%@page import=\"java.sql.ResultSet\"%>
 <%@page import=\"java.sql.PreparedStatement\"%>
 <%@page import=\"java.sql.DriverManager\"%>
 <%@page import=\"java.sql.Connection\"%>
 <%@page contentType=\"text/html\" pageEncoding=\"UTF-8\"%>
 <!DOCTYPE html>
 <html>
 <head>
 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
 <title>Mail Send</title>
 <style type=\"text/css\">
 a
 {
 text-decoration: none;
 font-family: sans-serif;
 font-size: 18pt;
 font-style: normal;
 color: yellow;
 }
 a:hover
 {
 text-decoration: none;
 font-family: cursive;
 font-size: 19pt;
 font-style: italic;
 color: aqua;
 }
 body
 {
 background-color: #005CFF;
 color: white;
 font-size: 18pt;
 font-family: cursive;
 }
 </style>
 </head>
 <body>
   
 <center>
   
 <h1>your mail has been sent</h1>
   
<%
 try {
 int spam_key_count = 0;
 String ipAddr = request.getRemoteAddr();
Class.forName(\"com.mysql.jdbc.Driver\");
 Connection conn = DriverManager.getConnection(\"jdbc:mysql://localhost:3306/spam\", \"root\", \"root\");
 //to get the count
 PreparedStatement ps = conn.prepareStatement(\"select count(id) from emailsend\");
 ResultSet rs = ps.executeQuery();
 rs.next();
 int db_col_count = rs.getInt(1);
 // to get the last record
 PreparedStatement pss = conn.prepareStatement(\"select msg from emailsend where id=?\");
 pss.setInt(1, db_col_count);
 ResultSet rss = pss.executeQuery();
 rss.next();
 String db_msg = rss.getString(1);
 // out.println(db_msg);
 String spam_keys = \"earn dollars make money job opportunities you have won\";
 StringTokenizer st = new StringTokenizer(spam_keys, \" \");
 while (st.hasMoreElements()) {
 String spam_token = (String) st.nextElement();
 // out.println(\"\" + spam_token);
 if (db_msg.contains(spam_token)) {
 spam_key_count++;
 }
 }
 // out.println(\"Count: \" + spam_key_count);
 if (spam_key_count >= 3) {
 int spamcount = 1;
 int nonspamcount = 0;
 PreparedStatement ps1 = conn.prepareStatement(\"insert into slog(ipaddress,spamcount,nonspamcount) values(?,?,?)\");
 ps1.setString(1, ipAddr);
 ps1.setInt(2, spamcount);
 ps1.setInt(3, nonspamcount);
 int i = ps1.executeUpdate();
 } else {
 int spamcount = 0;
 int nonspamcount = 1;
 PreparedStatement ps1 = conn.prepareStatement(\"insert into slog(ipaddress,spamcount,nonspamcount) values(?,?,?)\");
 ps1.setString(1, ipAddr);
 ps1.setInt(2, spamcount);
 ps1.setInt(3, nonspamcount);
 int i = ps1.executeUpdate();
 }
 } catch (Exception e) {
 out.println(\"Error: \" + e.getMessage());
 }
 %>
 <a href=\"index.html\">Back</a>
 </center>
 </body>
 </html>
I Have number files of this project but server not support to send entirer data.i will send link to you








