javax.mail.Transport.addConnectionListener()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(1.7k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中javax.mail.Transport.addConnectionListener()方法的一些代码示例,展示了Transport.addConnectionListener()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Transport.addConnectionListener()方法的具体详情如下:
包路径:javax.mail.Transport
类名称:Transport
方法名:addConnectionListener

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);

相关文章