concept email in category camel

appears as: email, email, n email
Camel in Action

This is an excerpt from Manning's book Camel in Action.

Three pieces of information in the email must be replaced at runtime with real values. You need to adjust the email to use the Velocity template language, and then place it into the source repository as src/test/resources/email.vm:

6.8 Working with email

It's hard to think of a more pervasive technology than email in the enterprise. Modern businesses, for better or worse, run on email. Compared to the other communication mechanisms mentioned thus far, email is certainly different. Whereas other components are primarily used to communicate with other automated services, email is most often used to communicate with people. A retail application may need to notify a customer that an order has been shipped, for instance. Or maybe a back-end system needs to send an alert to a system administrator about a failure. These are all ideal for email messaging. Sure, technically you can implement inter-application messaging with email if you want to, but that isn’t the most efficient way to do things.

Camel provides several components to work with email:

  • Mail component—This is the primary component for sending and receiving email in Camel.
  • AWS-SES component—Allows you to send email by using the Amazon Simple Email Service (SES).
  • Sending an email is then simple. For example, let’s say Jon wants to send an email to Claus about Camel. Using ProducerTemplate, you could do something like this:

    template.sendBody( "smtp://jon@localhost?password=secret&to=claus@localhost", "Yes, Camel rocks!");

    Here, you’re logging into an email server on localhost port 25 with username jon and password secret. You’re sending to the email address claus@localhost. Because you didn’t specify a From option, the From email field is defaulted to camel@localhost. Now the string you passed as a message body will become the body of the email. Typically, though, you’d like to have a subject for the email. You could add a subject option to the URI or add a subject header to the message. Let’s try to add a subject header: