<%@ page import="java.util.*" %> <%@ page import="java.util.Map.Entry" %> <%@ page import="java.util.ArrayList"%> <%@ page import="java.util.List"%> <%@ page import="java.util.Enumeration" %> <%@ page import="javax.mail.*" %> <%@ page import="javax.mail.internet.*" %> <%@ page import="javax.activation.*" %> <%@ page import="java.util.Date.*" %> <% String host = "mail.edc.ds1.usda.gov"; //String target = "FoodSafetyResources@fsis.usda.gov"; String target = request.getParameter("mailtoaddress"); String from = request.getParameter("from"); String subject = request.getParameter("subject"); String emailformat = request.getParameter("emailformat"); String domain = request.getServerName(); List excludedPara = new ArrayList(); excludedPara.add("mailtoaddress"); excludedPara.add("subject"); excludedPara.add("from"); excludedPara.add("emailformat"); //verfies that the request is from FSIS domain //System.out.println("send mail from domain= " + domain); if(domain.equalsIgnoreCase("www.fsis.usda.gov") || domain.equalsIgnoreCase("199.134.161.17")){ String body = ""; if(emailformat == null || emailformat.trim().length()==0 ){ Map parameters = request.getParameterMap(); Set set = parameters.entrySet(); Iterator it = set.iterator(); while (it.hasNext()) { // body += ""; Map.Entry entry = (Entry) it.next(); String paramName = entry.getKey(); if(!excludedPara.contains (paramName)){ String[] pValues = entry.getValue(); body += ""; for(int i=1; i"; } } } } else{ //string split on special character "|" String[] splits = emailformat.split("\\|"); // two \\ is required because "\" itself require escaping for(String paramName: splits){ String[] pValues = request.getParameterValues(paramName); if(pValues != null){ body += ""; for(int i=1; i"; } } } } body += "
"+parameter+": "+parameters.get(parameter)[0]+"
"+paramName+": "+pValues[0]+"
"+paramName+": "+pValues[0]+"
"; Date dtnow = new Date(); String dt = "


" + dtnow; String messageText = body+dt; boolean sessionDebug = false; // Create some properties and get the default Session. Properties props = System.getProperties(); props.put("mail.host", host); props.put("mail.transport.protocol", "smtp"); Session mailSession = Session.getDefaultInstance(props, null); // Set debug on the Session // Passing false will not echo debug info, and passing True will. mailSession.setDebug(sessionDebug); // Instantiate a new MimeMessage and fill it with the // required information. Message msg = new MimeMessage(mailSession); msg.setFrom(new InternetAddress(from)); InternetAddress[] address = {new InternetAddress(target)}; msg.setRecipients(Message.RecipientType.TO, address); msg.setSubject(subject); msg.setSentDate(new Date()); msg.setContent(messageText,"text/html"); // Hand the message to the default transport service // for delivery. Transport.send(msg); %> <% } %>