Skip to Main Content
Spring: A Developer's Notebook
book

Spring: A Developer's Notebook

by Bruce Tate, Justin Gehtland
April 2005
Intermediate to advanced content levelIntermediate to advanced
216 pages
4h 44m
English
O'Reilly Media, Inc.
Content preview from Spring: A Developer's Notebook

Chapter 8. Messaging and Remoting

In early 2001, the sun was shining, but I got a call from another kayaker named Steve Daniel saying that North Grape Creek was runnable, but below flood stage. It had never been run before. It required access through private property, and had to be at a perfect level: high enough to run, and low enough to navigate the many low-water crossings that dot the Texas country side. I wondered how Steve timed it perfectly.

Sending Email Messages

In Chapter 6, you learned how to attach behaviors to a bean. You built an example to write a message to a database whenever an exception was thrown. But it would be much more useful to have an email message sent to you when something breaks. Let's use Spring's email abstraction to do that.

How do I do that?

Spring provides a set of services to help you quickly send email messages. You'll need to use three classes to get the support:

  • The SimpleMailMessage class is a value object that has the mail properties that you'll need, such as subject, body, to, from, and cc properties.

  • The MailException is thrown when something breaks.

  • The MailSender interface and JavaMailSender provide Spring's implementation to send messages. You will, of course, need to configure a mail client.

First, you'll need to configure a simple message. Do that in the context, like in Example 8-1.

Example 8-1. RentABike-servlet.xml

<bean id="mailMessage" class="org.springframework.mail.SimpleMailMessage"> <property name="to"><value>itsupport@rentabike.com</value></property> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

JavaBeans Unleashed

JavaBeans Unleashed

Dr. Donald Doherty, Rick Leinecker
Beginning Spring

Beginning Spring

Mert Caliskan, Kenan Sevindik, Rod Johnson, Jürgen Höller
Hibernate Search in Action

Hibernate Search in Action

Emmanuel Bernard, John Griffin

Publisher Resources

ISBN: 0596009100Supplemental ContentErrata Page