I need to send e-mails from a servlet running within Tomcat. I\'ll always send to the same recipient with the same subject, but with different contents.
What\'s a sim
I usually define my javamail session in the GlobalNamingResources section of tomcat's server.xml file so that my code does not depend on the configuration parameters:
...
and I get the session via JNDI:
Context context = new InitialContext();
Session sess = (Session) context.lookup("java:comp/env/mail/Mail");
MimeMessage message = new MimeMessage(sess);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject(subject, "UTF-8");
message.setText(content, "UTF-8");
Transport.send(message);