<%@ page import="java.util.Properties" %> <%@ page import="javax.mail.*" %> <%@ page import="javax.mail.internet.*" %> <% // Step 1: Get fields from index.jsp final String to = request.getParameter("LMemail"); out.println(to); final String subject = "Leave request// leave Application!"; final String messageText = "Dear Line Manager,\n" + "You have a new Leave request \n" + "Please login to CLINIHR to view details."; // Step 2: Sender's email ID and password final String from = "dipti.yelve@clinicaresearch.com"; final String pass = "Clinica@068"; // Step 3: Define host String host = "mail.clinicaresearch.com"; // Step 4: Create Properties class object Properties props = new Properties(); props.put("mail.smtp.host", host); props.put("mail.transport.protocol", "smtp"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.user", from); props.put("mail.password", pass); props.put("mail.smtp.port", "587"); props.put("mail.smtp.ssl.trust", "*"); // Step 5: Get the Session object Session mailSession = Session.getInstance(props, new javax.mail.Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(from, pass); } }); // Step 6: Create MimeMessage object MimeMessage message = new MimeMessage(mailSession); try { // Step 7: Set From and all required fields message.setFrom(new InternetAddress(from)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); message.setSubject(subject); message.setText(messageText); // Step 9: Send message using Transport class Transport.send(message); // Step 10: Display successful message response.sendRedirect("leaveApp.jsp?msg=done"); } catch (MessagingException e) { //throw new RuntimeException(e); //response.sendRedirect("leaveApp.jsp?msg=wrong"); } %>