List of usage examples for org.apache.commons.net.smtp AuthenticatingSMTPClient login
public boolean login(String hostname) throws IOException
From source file:net.metanotion.emailqueue.SmtpSender.java
@Override public Connection getConnection() { AuthenticatingSMTPClient client = null; try {/* www . j a v a 2 s . c om*/ client = new AuthenticatingSMTPClient(); client.addProtocolCommandListener(new ProtocolCommandListener() { @Override public void protocolCommandSent(final ProtocolCommandEvent event) { logger.trace(COMMAND_LOG_FORMAT, event.getCommand(), event.getMessage()); } @Override public void protocolReplyReceived(final ProtocolCommandEvent event) { logger.trace(COMMAND_LOG_FORMAT, event.getCommand(), event.getMessage()); } }); logger.trace("Connecting"); client.connect(this.server, this.port); if (!SMTPReply.isPositiveCompletion(client.getReplyCode())) { logger.error("Did not get positive completion."); throw new IOException("Could not complete SMTP connection."); } startTls(client); logger.trace("Authenticating"); client.auth(AuthenticatingSMTPClient.AUTH_METHOD.PLAIN, username, password); logger.trace("Login"); client.login(host); return new Connection(client); } catch (final IOException | NoSuchAlgorithmException | InvalidKeyException | InvalidKeySpecException ex) { logger.debug("Error", ex); try { if (client != null) { client.disconnect(); } } catch (final IOException ex2) { } throw new RuntimeException(ex); } }