The Spring Framework allows a very simple way to send e-mails.
/* Create a MIME message */
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, "UTF-8");
helper.setTo("My friend <[email protected]>");
helper.setFrom("Myself <[email protected]>");
helper.setSubject("The subject");
/* Send plaintext */
String plaintext = "The text of the mail";
helper.setText(plaintext, false);
/* Send html */
String htmltext = "<html><body><p>The text of the mail</p></body></html>";
//helper.setText(htmltext, true);
/* Send both (multipart) */
//helper.setText(plaintext, htmltext);
mailSender.send(message);
The mailSender can be injected with the following xml in the application context.
<bean id="mailSender"
class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host"><value>mail.server.com</value></property>
<property name="username"><value>smtpusername</value></property>
<property name="password"><value>smtppassword</value></property>
</bean>
You gotta love the simplicity of it.
Please check “ozacc-mail library”. It’s more flexible than spring-mail.
http://translate.google.com/translate?hl=en&sl=ja&u=http://spring-ext.sourceforge.jp/oml/
Sorry, but documentation in japanese is a real blocker.
Sorry, too. The creator of ozacc-mail library releases “Maven Repo Search”.