I'm sending emails using Apache commons email lib.
However, I'm unable to listen to Connection and Transport events. I have added event listeners using:
email.getMailSession().getTransport().addConnectionListener(this);
email.getMailSession().getTransport().addTransportListener(this);
...but don't receive any events.
My code is as follows:
public class MailSendTest implements ConnectionListener, TransportListener{
final Email email = new SimpleEmail();
public void sendEmail(){
try {
email.setHostName("smtp.host.com");
email.setFrom("from@host.com");
email.addTo("to@host.com");
email.setBounceAddress("from@host.com");
email.setSubject("Testing");
email.setMsg("Test Message");
email.setDebug(true);
email.setAuthentication("from@host.com", "pass");
email.setSslSmtpPort("465");
email.setSocketTimeout(60000);
email.getMailSession().getTransport().addConnectionListener(this);
email.getMailSession().getTransport().addTransportListener(this);
email.send();
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Err : "+ex.getMessage());
}
}
@Override
public void opened(ConnectionEvent e) {
System.out.println("####Connected to "+ email.getHostName());
}
@Override
public void disconnected(ConnectionEvent e) {
System.out.println("####Disconnected from "+ email.getHostName());
}
@Override...
}
Any help would be appreciated.