<%@ page import = "java.util.*"%> <%@ page import = "javax.mail.*"%> <%@ page import = "javax.mail.internet.*"%> <%@ page import = "javax.activation.*" %> <% // change accordingly String to = "receipient@mail.com"; // change accordingly String from = "sender@office365account.com"; // or IP address String host = "smtp.office365.com"; // mail id String username = ""; // correct password for gmail id String password = "pwd"; System.out.println("TLSEmail Start"); // Get the session object // Get system properties Properties properties = System.getProperties(); // Setup mail server properties.setProperty("mail.smtp.host", host); // SSL Port properties.put("mail.smtp.port", "587"); // enable authentication properties.put("mail.smtp.auth", "true"); // SSL Factory properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); properties.put("mail.smtp.starttls.enable","true"); properties.put("mail.transport.protocol","smtp"); // creating Session instance referenced to // Authenticator object to pass in // Session.getInstance argument Session session1 = Session.getInstance(properties, new javax.mail.Authenticator() { // override the getPasswordAuthentication // method protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("", "pwd"); } }); try { // javax.mail.internet.MimeMessage class is mostly // used for abstraction. MimeMessage message = new MimeMessage(session1); // header field of the header. message.setFrom(new InternetAddress(from)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); message.setSubject("It worked yo!"); message.setText("Eat my shorts"); // Send message Transport.send(message); System.out.println("Yo it has been sent.."); } catch (MessagingException mex) { mex.printStackTrace(); } %> Send HTML Email using JSP

Send Email using JSP

<% //out.println("Result: " + result + "\n"); %>