本文整理了Java中javax.mail.Transport.addConnectionListener()
方法的一些代码示例,展示了Transport.addConnectionListener()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Transport.addConnectionListener()
方法的具体详情如下:
包路径:javax.mail.Transport
类名称:Transport
方法名:addConnectionListener
暂无
代码示例来源:origin: stackoverflow.com
final SettableFuture<Boolean> future = SettableFuture.create();
Transport transport = null;
try {
transport = session.getTransport("smtp");
transport.addConnectionListener(new ConnectionListener() {
@Override
public void opened(ConnectionEvent connectionEvent) {
future.set(((SMTPTransport) connectionEvent.getSource()).isConnected());
}
@Override
public void disconnected(ConnectionEvent connectionEvent) {
}
@Override
public void closed(ConnectionEvent connectionEvent) {
}
});
transport.connect(config.getMailSMTPHost(),
config.getMailSMTPPort(),
config.getMailUsername(),
config.getMailPassword());
} catch (final MessagingException e) {
future.setException(e);
} finally{
if(transport != null){
transport.close();
}
}
return future;
代码示例来源:origin: spajus/gmail4j
/**
* Gets Gmail {@link Transport}
*
* @return Configured and ready for use Transport
*/
public Transport getTransport() {
try {
final Transport transport = getSession().getTransport();
transport.addConnectionListener(new ImapConnectionHandler(
new ConnectionInfo(loginCredentials.getUsername(),
gmailSmtpHost,
gmailSmtpPort)));
transport.connect(loginCredentials.getUsername(),
new String(loginCredentials.getPasword()));
return transport;
} catch (final Exception e) {
throw new GmailException("ImapGmailClient requires ImapGmailConnection!");
}
}
代码示例来源:origin: com.helger/ph-smtp
aTransport.addConnectionListener (aConnectionListener);
内容来源于网络,如有侵权,请联系作者删除!