/* * @(#)MailSenderServlet.java 1.00 2/17/2000 */ /* ***************************************************************************** Copyright 2000 by Erica Andrews (cylikon@hotmail.com). All rights reserved. ./ButchWhipAppeal/ ./IcedPinky/ NO portion of this software may be used in ANY way by anyone other than myself without my express written consent. If it is downloaded for testing, it must be deleted from your system within 24 hours. Any other use constitutes piracy and fraudulent misuse of this software, punishable in a court of law. Copyright 2000 by Erica Andrews. All rights reserved. ***************************************************************************** */ import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.net.InetAddress; import java.util.Properties; import javax.mail.*; import javax.mail.internet.*; /** * MailSenderServlet class. * @author cylikon@hotmail.com * @version 1.00 02/17/2000 */ public class MailSenderServlet extends HttpServlet { public String TO = "whip1472@www.whip.com"; // a domain name only existant on my computer public String HOST = "127.0.0.1"; // loopback localhost public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // setting up the print writer and mime type PrintWriter out = response.getWriter(); response.setContentType("text/html"); String FROM = request.getParameter("from"); String SUBJECT = request.getParameter("subject"); String MESSAGE = request.getParameter("message"); String userinfo = request.getParameter("userinfo"); InetAddress here = InetAddress.getLocalHost(); // the following string is used to collect some information about the user, the site they saw, URL referrer and their browser String UserI = "\n URL: "+request.getRequestURI()+"\n Method: "+request.getMethod()+"\n Servlet Path: "+request.getServletPath()+"\n Query String: "+request.getQueryString()+"\n Remote User: "+request.getRemoteUser()+"\n Remote Address: "+request.getRemoteAddr()+"\n Remote Host: "+request.getRemoteHost()+"\n Web Browser: "+request.getHeader("User-Agent")+"\n\n Connected on Server : "+request.getServerName()+", IP:"+here.getHostAddress()+",Port:"+request.getServerPort(); // first dealing with cases in which the user is seeing the mail page for the first time and have not sent anything yet if (FROM == null && SUBJECT == null && MESSAGE == null) { out.print("Use this form to send your comments, suggestions, compliments, and to report any problems you found while using this site.

From:
Subject:

Your Message:

"); // now, dealing with cases in which the user has tried to send something in the mail form. } else { if (FROM.equals("")) { out.print("An error occurred: No FROM address was provided. Please try again.

Your email was as follows:

From: "+FROM+"
Subject: "+SUBJECT+"
Message: "+MESSAGE); } else if (MESSAGE.equals("")) { out.print("An error occured: No MESSAGE was provided. No empty emails, please.

Your email was as follows:

From: "+FROM+"
Subject: "+SUBJECT+"
Message: "+MESSAGE); } else { try { // some simple mail validation // blocking emails in which the user supplied no FROM email address or no message // If they supplied both a message and a return email address, let's try to send the mail Session s = Session.getDefaultInstance(System.getProperties(),null); MimeMessage m = new MimeMessage(s); InternetAddress t = new InternetAddress(TO); InternetAddress f = new InternetAddress(FROM); m.addRecipients(Message.RecipientType.TO, new InternetAddress[]{t }); // TO addresss m.setFrom(f); // the FROM address m.setSubject("CJs IIS Site Comments: "+SUBJECT); // message subject m.setContent(MESSAGE+"\n\n Sender Info:"+UserI, "text/plain"); // message body m.setHeader("X-Mailer", "JavaMail API on JSP"); m.addHeaderLine("Email message sent using the JavaMail API on CJs IIS website"); // -- setting mail Priority for "high" in case the user is reporting site problems m.setHeader("X-Priority", "1"); m.setHeader("x-msmail-priority", "high"); Transport.send(m); // sending the actual mail out.print("
End of Mail Session: Your mail has been successfully sent to the site owner. Your email was as follows:

From: "+FROM+"
Subject: "+SUBJECT+"
Message: "+MESSAGE+"

"); } catch (AddressException ae) { out.print("Problem sending mail...You did not provide a valid FROM address.");} catch (MessagingException me) { out.print("Problem sending mail... " +me+" "+me.getMessage());} //end of Try } // end embedded if - else } //end of long else statement } // end of doGet method public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // setting up the print writer and mime type PrintWriter out = response.getWriter(); response.setContentType("text/html"); String FROM = request.getParameter("from"); String SUBJECT = request.getParameter("subject"); String MESSAGE = request.getParameter("message"); String userinfo = request.getParameter("userinfo"); InetAddress here = InetAddress.getLocalHost(); // the following string is used to collect some information about the user, the site they saw, URL referrer and their browser String UserI = "\n URL: "+request.getRequestURI()+"\n Method: "+request.getMethod()+"\n Servlet Path: "+request.getServletPath()+"\n Query String: "+request.getQueryString()+"\n Remote User: "+request.getRemoteUser()+"\n Remote Address: "+request.getRemoteAddr()+"\n Remote Host: "+request.getRemoteHost()+"\n Web Browser: "+request.getHeader("User-Agent")+"\n\n Connected on Server : "+request.getServerName()+", IP:"+here.getHostAddress()+",Port:"+request.getServerPort(); // first dealing with cases in which the user is seeing the mail page for the first time and have not sent anything yet if (FROM == null && SUBJECT == null && MESSAGE == null) { out.print("Use this form to send your comments, suggestions, compliments, and to report any problems you found while using this site.

From:
Subject:

Your Message:

"); // now, dealing with cases in which the user has tried to send something in the mail form. } else { if (FROM.equals("")) { out.print("An error occurred: No FROM address was provided. Please try again.

Your email was as follows:

From: "+FROM+"
Subject: "+SUBJECT+"
Message: "+MESSAGE); } else if (MESSAGE.equals("")) { out.print("An error occured: No MESSAGE was provided. No empty emails, please.

Your email was as follows:

From: "+FROM+"
Subject: "+SUBJECT+"
Message: "+MESSAGE); } else { try { // some simple mail validation // blocking emails in which the user supplied no FROM email address or no message // If they supplied both a message and a return email address, let's try to send the mail Session s = Session.getDefaultInstance(System.getProperties(),null); MimeMessage m = new MimeMessage(s); InternetAddress t = new InternetAddress(TO); InternetAddress f = new InternetAddress(FROM); m.addRecipients(Message.RecipientType.TO, new InternetAddress[]{t }); // TO addresss m.setFrom(f); // the FROM address m.setSubject("CJs IIS Site Comments: "+SUBJECT); // message subject m.setContent(MESSAGE+"\n\n Sender Info:"+UserI, "text/plain"); // message body m.setHeader("X-Mailer", "JavaMail API on JSP"); m.addHeaderLine("Email message sent using the JavaMail API on CJs IIS website"); // -- setting mail Priority for "high" in case the user is reporting site problems m.setHeader("X-Priority", "1"); m.setHeader("x-msmail-priority", "high"); Transport.send(m); // sending the actual mail out.print("
End of Mail Session: Your mail has been successfully sent to the site owner. Your email was as follows:

From: "+FROM+"
Subject: "+SUBJECT+"
Message: "+MESSAGE+"

"); } catch (AddressException ae) { out.print("Problem sending mail...You did not provide a valid FROM address.");} catch (MessagingException me) { out.print("Problem sending mail... " +me+" "+me.getMessage());} //end of Try } // end embedded if - else } //end of long else statement } // end of doPost method } // end of Class