final Session smtpSession,
final Message message)
throws OmhException {
// Get the transport from the session.
SMTPTransport transport;
try {
transport =
(SMTPTransport) smtpSession.getTransport(MAIL_PROTOCOL);
}
catch(NoSuchProviderException e) {
throw
new OmhException(
"There is no provider for " + MAIL_PROTOCOL + ".",
e);
}
// Connect to the transport.
try {
transport.connect();
}
catch(MessagingException e) {
throw new OmhException("Could not connect to the mail server.", e);
}
// Send the message.
try {
transport.sendMessage(message, message.getAllRecipients());
}
catch(SendFailedException e) {
throw new OmhException("Failed to send the message.", e);
}
catch(MessagingException e) {
throw
new OmhException(
"There was a problem while sending the message.",
e);
}
finally {
// Close the connection to the transport.
try {
transport.close();
}
catch(MessagingException e) {
LOGGER
.log(
Level.WARNING,