tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Garthfield Carter <>
Subject JavaMail SMTP authentication in JSP
Date Fri, 13 Jul 2007 10:07:30 GMT

Has anybody got an example they could send me of how to authenticate 
with an SMTP server to send an email in JSP for JavaMail? I've been 
trying unsuccessfully for two days trying to get something working. I'm 
just trying in plain text at the moment, I don't need SSL or anything. 
Below is the non-functioning code example I've built from various 
examples on Google. None of the examples on Google that I searched for 
gave a complete example just snippets. There's something that I'm doing 

Any helpe would be greatly appreciated.


<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>


String host = "";
String user = "";
String pass = "pAsWoRd";

String to = "";
String from = "";
String subject = "Test subject";
String messageText = "Test body";
boolean sessionDebug = false;

Properties props = System.getProperties();
props.put("", host);
props.put("mail.transport.protocol", "smtp");

Session mailSession = Session.getDefaultInstance(props, null);

Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSentDate(new Date());

Transport transport = mailSession.getTransport("smtp");
transport.connect(host, user, user);
transport.sendMessage(msg, msg.getAllRecipients());


To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message