<%@ page import="java.util.*" %> <%@ page import="javax.mail.*" %> <%@ page import="javax.mail.internet.*" %> <%@ page import="javax.activation.*" %> Official Website of Corpcraft - <%! // CONSTANTS declaration String SUBMIT_BUTTON = "SUBMIT"; String SUCCESS = "SUCCESS"; String REG_TYPE_INDIVIDUAL = "Individual"; String REG_TYPE_CORPORATE = "Corporate"; String CHECKED = "checked"; %> <% String selectedRegType = request.getParameter("regType"); String individualChecked = ""; String corporateChecked = ""; String optionalRequired = ""; String optionalRequiredPart = ""; String readOnly = ""; String dispCorp = "none"; String dispPart = "block"; //String from = ""; if( REG_TYPE_CORPORATE.equals(selectedRegType) ){ dispCorp = "block"; corporateChecked = CHECKED; optionalRequired = "required=\"true\""; dispPart = "none"; //from = request.getParameter("sponsorEmail"); } else{ individualChecked = CHECKED; optionalRequiredPart = "required=\"true\""; readOnly = "readonly"; //from = request.getParameter("email"); } %> <%! public String buildMessage(String regType, HttpServletRequest request){ String messageText = ""; messageText = " Program Name:\t\t\t"+request.getParameter("programName"); //messageText += "\n Program Date:\t\t\t"+request.getParameter("programDate"); messageText += "\n Number of Participants:\t\t\t"+request.getParameter("numCandidates"); messageText += "\n Registration Type:\t\t\t"+request.getParameter("regType"); if( REG_TYPE_INDIVIDUAL.equals(regType) ){ messageText += "\n Participant Name:\t\t\t"+request.getParameter("participantName"); messageText += "\n Job Title:\t\t\t"+request.getParameter("jobTitle"); messageText += "\n Email:\t\t\t"+request.getParameter("email"); messageText += "\n Phone:\t\t\t"+request.getParameter("phone"); } else{ messageText += "\n Sponsor:\n Name:\t\t\t"+request.getParameter("sponsorName"); messageText += "\n Position:\t\t\t"+request.getParameter("position"); messageText += "\n Email:\t\t\t"+request.getParameter("sponsorEmail"); messageText += "\n Phone:\t\t\t"+request.getParameter("sponsorPhone"); messageText += "\n Address:\t\t\t"+request.getParameter("sponsorAddress"); messageText += "\n Country:\t\t\t"+request.getParameter("sponsorCountry"); messageText += "\n Special Request:\t\t\t"+request.getParameter("specialRequest"); } return messageText; } %> <% // CODE for sending email String submit = request.getParameter("submitButton"); String excp = ""; boolean isRegistrationSuccess = false; boolean isFormSubmitted = false; Object success = request.getSession(true).getAttribute(SUBMIT_BUTTON); if( success != null ){ isRegistrationSuccess = SUCCESS.equals((String)success); } if(SUBMIT_BUTTON.equals(submit) && !isRegistrationSuccess) { String host = "relay-hosting.secureserver.net"; String to = "info@corpcraft.com"; String from = "corpcraft@corpcraft.com"; String pass = "ccPasscc"; String subject = "Registration:: "+selectedRegType+" :: "+request.getParameter("programName"); String messageText = ""+buildMessage( selectedRegType, request); isFormSubmitted = true; try{ 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"); props.put("mail.smtp.auth", "true"); props.put("mail.user", from); props.put("mail.password",pass); excp = "Props "; Session mailSession = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("corpcraft@corpcraft.com","ccPasscc"); } } ); Transport transport = mailSession.getTransport("smtp"); excp = "Access to default session "; // 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(to)}; msg.setRecipients(Message.RecipientType.TO, address); msg.setSubject(subject); msg.setSentDate(new Date()); msg.setText(messageText); // Hand the message to the default transport service // for delivery. excp = "About to send msg "; transport.connect(host, from,pass); excp = "Connected. Sending... "; transport.sendMessage(msg, msg.getRecipients(Message.RecipientType.TO)); transport.close(); excp = "Sent "; //Transport.send(msg); isRegistrationSuccess = true; request.getSession(true).setAttribute(SUBMIT_BUTTON, SUCCESS); }catch(Exception e){ excp += e.toString(); e.printStackTrace(); } } %>

Register

 All Rights Reserved    Copyright © 2011 Corpcraft.com

<%-- <%=excp%> --%> <% if(isRegistrationSuccess){ %> Thank you for registering with Corp Craft. We will contact you shortly.
<% } else { %>
<%-- --%>
Program Title
      
Program Date    
Number of People that would attend:    >
Registration     onClick="if(this.checked){toggleSponsor()}" value="<%=REG_TYPE_INDIVIDUAL%>" required="true" invalidMessage="Please select an option." onchange="toggleSponsor()">        onClick="if(this.checked){toggleSponsor()}" value="<%=REG_TYPE_CORPORATE%>" required="true" invalidMessage="Please select an option." onchange="toggleSponsor()">

Participant:
Name:     invalidMessage="Alphabets only.">
Job Title:     >
Email     >
Phone: + invalidMessage="Invalid Phone number.">  (Ex: +919880454545 or +918026262626)


<%}%>