That's all the code you need to write! However, to get it to compile, you need to update the POM file
to include the Java mail dependencies. Listing 9-57 shows the additions required to build the updated
Listing 9-57. Java Mail Dependency
To wire all this up, start by configuring Spring to be able to send e-mails in the first place. Using
Spring's org.springframework.mail.javamail.JavaMailSenderImpl lets you configure where the SMTP
server is and the appropriate values for it. Listing 9-58 shows the configuration that goes in launch-
context.xml for this bean.
Listing 9-58. Configuring JavaMailSenderImpl
<property name="host" value="smtp.gmail.com"/>
<property name="port" value="587"/>
<property name="username" value="someusername"/>
<property name="password" value="somepassword"/>
To be able to test the e-mail sending capabilities, you use Google's Gmail SMTP functionality as the
mail server. Listing 9-58 shows the configuration required. All you need to do is replace the username
and password with your Gmail username and password. 5
Next, you can move on to configuring the job to process the new customers. To configure the input
for the first step, you configure a resource to read from that is passed from the command line, and a
FlatFileItemReader that reads in the customerWithEmail.csv file. The writer for step 1 consists of the
previously mentioned JdbcBatchItemWriter using the dataSource , a provided preparedStatement , and
the CustomerItemPreparedStatementSetter coded in Listing 9-54. Listing 9-59 shows how you wire that
up for the first step in the job.
5 Unlike most SMTP servers used by enterprises, the Gmail server you're using for this example ignores
the from attribute of the e-mail when it's sent and replaces it with the name of the account from which
you logged in.