Paste the code below into a jsp, place ‘mail.jar’ and ‘activation.jar’ below into the lib folder of a war. Upload the war and run the jsp. the war is also included below for clarity.
<%@ page import="javax.mail.*,javax.mail.internet.*,javax.mail.internet.MimeMessage.RecipientType,java.io.*,java.util.Properties" %> <% Properties props = new Properties(); props.put("mail.smtp.host", "localhost"); Session mailsession = Session.getDefaultInstance(props, null); Message msg = new MimeMessage(mailsession); //set the from and to address InternetAddress addressFrom; try { addressFrom = new InternetAddress("xxx@hyve.com"); msg.setFrom(addressFrom); InternetAddress addressTo = new InternetAddress("xxx@hyve.com"); msg.setRecipient(RecipientType.TO,addressTo); msg.setSubject("subject"); msg.setContent("HELLO", "text/html"); Transport.send(msg); } catch (Exception e) { e.printStackTrace(); } %>
Tags:
JSP