Java Reference
In-Depth Information
public void notifyCopyError(String srcDir, String destDir, String filename) {
SimpleMailMessage message = new SimpleMailMessage();
message.setSubject("File Copy Error");
"Dear Administrator,\n\n" +
"An error occurred when copying the following file :\n" +
"Source directory : " + srcDir + "\n" +
"Destination directory : " + destDir + "\n" +
"Filename : " + filename);
Next, you have to configure a MailSender implementation in the bean configuration file and inject it
into EmailErrorNotifier . In Spring, the unique implementation of this interface is JavaMailSenderImpl ,
which uses JavaMail to send e-mail.
<beans ...>
<bean id="mailSender"
<property name="host" value="localhost" />
<property name="port" value="25" />
<property name="username" value="system" />
<property name="password" value="12345" />
<bean id="errorNotifier"
<property name="mailSender" ref="mailSender" />
The default port used by JavaMailSenderImpl is the standard SMTP port 25, so if your e-mail server
listens on this port for SMTP, you can simply omit this property. Also, if your SMTP server doesn't
require user authentication, you needn't set the username and password.
If you have a JavaMail session configured in your Java EE application server, you can first look it up
with the help of JndiObjectFactoryBean .
<bean id="mailSession"
<property name="jndiName" value="mail/Session" />
Or you can look up a JavaMail session through the <jee:jndi-lookup> element if you are using
Spring 2.0 or later.
<jee:jndi-lookup id="mailSession" jndi-name="mail/Session" />
You can inject the JavaMail session into JavaMailSenderImpl for its use. In this case, you no longer
need to set the host, port, username, or password.
Search WWH ::

Custom Search