use of javax.mail.Transport in project jmeter by apache.
the class SendMailCommand method execute.
/**
* Sends message to mailserver, waiting for delivery if using synchronous
* mode.
*
* @param message
* Message previously prepared by prepareMessage()
* @throws MessagingException
* when problems sending the mail arise
* @throws InterruptedException
* when interrupted while waiting for delivery in synchronous
* mode
*/
public void execute(Message message) throws MessagingException, InterruptedException {
Transport tr = null;
try {
tr = session.getTransport(getProtocol());
SynchronousTransportListener listener = null;
if (synchronousMode) {
listener = new SynchronousTransportListener();
tr.addTransportListener(listener);
}
if (useAuthentication) {
tr.connect(smtpServer, username, password);
} else {
tr.connect();
}
tr.sendMessage(message, message.getAllRecipients());
if (listener != null) /*synchronousMode==true*/
{
// listener cannot be null here
listener.attend();
}
} finally {
if (tr != null) {
try {
tr.close();
} catch (Exception e) {
// NOOP
}
}
logger.debug("transport closed");
}
logger.debug("message sent");
}
Aggregations