Example usage for org.apache.commons.net.smtp SMTPConnectionClosedException getMessage

List of usage examples for org.apache.commons.net.smtp SMTPConnectionClosedException getMessage

Introduction

In this page you can find the example usage for org.apache.commons.net.smtp SMTPConnectionClosedException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:autohit.call.modules.SimpleSmtpModule.java

/**
 * Login method. It will fault if a session has not been started or has
 * expired. The hostname is optional; pass null if not used.
 * //  www.j a  v a  2s . co  m
 * @param hostname
 *           hostname to use instead of localhost.
 * @throws CallException
 */
private void login(String hostname) throws CallException {

    // Is it started?
    if (client == null) {
        this.fault("Session not start()'ed.");
    }

    try {
        if (hostname == null) {
            client.login();
        } else {
            client.login(hostname);
        }

        // what happened?
        int code = client.getReplyCode();
        if (code >= SMTP_ERROR_THRESHOLD) {
            this.error("Login failed with code=" + code + " reply=" + client.getReplyString());
        } else if (this.isDebugging()) {
            this.debug("Login complete.  code=" + code);
        }

    } catch (SMTPConnectionClosedException ex) {
        this.done();
        this.fault("Cannot login.  Connection expired and closed itself.");
    } catch (Exception ex) {
        this.done();
        this.fault("Cannot login due to exception.  message=" + ex.getMessage());
    }
}

From source file:autohit.call.modules.SimpleSmtpModule.java

/**
 * Sender method. It will fault if a session has not been started or has
 * expired. It will set the sender. Subsequent calls will overwrite the
 * value. The address should be a valid email address.
 * //from  w  ww  .j av a 2s.c o m
 * @param hostname
 *           hostname to use instead of localhost.
 * @throws CallException
 */
private void sender(String s) throws CallException {

    // Is it started?
    if (client == null) {
        this.fault("Session not start()'ed.");
    }

    try {
        client.setSender(s);

        // what happened?
        int code = client.getReplyCode();
        if (code >= SMTP_ERROR_THRESHOLD) {
            this.error("Sender failed with code=" + code + " reply=" + client.getReplyString());
        } else if (this.isDebugging()) {
            this.debug("Sender complete.  code=" + code);
        }

    } catch (SMTPConnectionClosedException ex) {
        this.done();
        this.fault("Cannot set sender.  Connection expired and closed itself.");
    } catch (Exception ex) {
        this.done();
        this.fault("Cannot set sender due to exception.  message=" + ex.getMessage());
    }
}

From source file:autohit.call.modules.SimpleSmtpModule.java

/**
 * Send the message in the text. Returns the SMTP reply code.
 * /*from  w w  w.  j  a  v a 2 s. co m*/
 * @param hostname
 *           hostname to use instead of localhost.
 * @throws CallException
 */
private String send(String text) throws CallException {

    String result = ERROR_STRING_FOR_FAILURE;

    // Is it started?
    if (client == null) {
        this.fault("Session not start()'ed.");
    }

    // Is there something to send? PARANOID
    if (text == null) {
        this.error("Nothing to send.");
        return result;
    }

    try {
        client.sendShortMessageData(text);
        //client.completePendingCommand(); // don't care if it was ok.
        result = Integer.toString(client.getReplyCode());

        // what happened?
        int code = client.getReplyCode();
        if (code >= SMTP_ERROR_THRESHOLD) {
            this.error("Message send FAILED.  code=" + code + " reply=" + client.getReplyString());
        } else if (this.isDebugging()) {
            this.debug("Message send complete.  code=" + code + " reply=" + client.getReplyString());
        }

    } catch (SMTPConnectionClosedException ex) {
        this.done();
        this.fault("Send failed.  Connection expired and closed itself.");
    } catch (Exception ex) {
        this.done();
        this.fault("Send failed due to exception.  message=" + ex.getMessage());
    } finally {
        this.done();
    }
    return result;
}

From source file:autohit.call.modules.SimpleSmtpModule.java

/**
 * Recipient method. It will fault if a session has not been started or has
 * expired. It will add a recipient. Subsequent calls will add to the list
 * of recipients. The address should be a valid email address. The only way
 * to clear the list is to call reset() and start over.
 * /*from ww w  . jav  a  2s . c  om*/
 * @param hostname
 *           hostname to use instead of localhost.
 * @throws CallException
 */
private void recipient(String s) throws CallException {

    // Is it started?
    if (client == null) {
        this.fault("Session not start()'ed.");
    }

    try {
        client.addRecipient(s);

        // what happened?
        int code = client.getReplyCode();
        if (code >= SMTP_ERROR_THRESHOLD) {
            this.error("Add recipient failed with code=" + code + " reply=" + client.getReplyString());
        } else if (this.isDebugging()) {
            this.debug("Add recipient complete.  code=" + code);
        }

    } catch (SMTPConnectionClosedException ex) {
        this.done();
        this.fault("Cannot add recipient.  Connection expired and closed itself.");
    } catch (Exception ex) {
        this.done();
        this.fault("Cannot add recipient due to exception.  message=" + ex.getMessage());
    }
}

From source file:autohit.call.modules.SimpleSmtpModule.java

/**
 * Sender relay method. It will fault if a session has not been started or
 * has expired. It will set the sender as the accumulated relay. You must
 * have called addsenderrelay() at least once or you will get an error.
 * Subsequent calls will overwrite the value.
 * /* w w  w  . ja  v  a2s  .  com*/
 * @param hostname
 *           hostname to use instead of localhost.
 * @throws CallException
 */
private void senderrelay() throws CallException {

    // Is it started?
    if (client == null) {
        this.fault("Session not start()'ed.");
    }

    // Is there a relay?
    if (senderrelay == null) {
        this.error(
                "Sender relay not ready.  You need to call addsenderrelay() at least once before this method.");
        return;
    }

    try {
        client.setSender(senderrelay);

        // what happened?
        int code = client.getReplyCode();
        if (code >= SMTP_ERROR_THRESHOLD) {
            this.error("Set sender relay failed with code=" + code + " reply=" + client.getReplyString());
        } else if (this.isDebugging()) {
            this.debug("Set sender relay complete.  code=" + code);
        }

    } catch (SMTPConnectionClosedException ex) {
        this.done();
        this.fault("Cannot set sender.  Connection expired and closed itself.");
    } catch (Exception ex) {
        this.done();
        this.fault("Cannot set sender due to exception.  message=" + ex.getMessage());
    }
}

From source file:autohit.call.modules.SimpleSmtpModule.java

/**
 * Recipient relay method. It will fault if a session has not been started
 * or has expired. It will set the sender as the accumulated relay. You
 * must have called addrecipientrelay() at least once or you will get an
 * error. Subsequent calls will overwrite the value.
 * // w w w.java 2s  .  com
 * @param hostname
 *           hostname to use instead of localhost.
 * @throws CallException
 */
private void recipientrelay() throws CallException {

    // Is it started?
    if (client == null) {
        this.fault("Session not start()'ed.");
    }

    // Is there a relay?
    if (recipientrelay == null) {
        this.error(
                "Recipient relay not ready.  You need to call addrecipientrelay() at least once before this method.");
        return;
    }

    try {
        client.addRecipient(recipientrelay);

        // what happened?
        int code = client.getReplyCode();
        if (code >= SMTP_ERROR_THRESHOLD) {
            this.error("Add recipient relay failed with code=" + code + " reply=" + client.getReplyString());
        } else if (this.isDebugging()) {
            this.debug("Add recipient relay complete.  code=" + code);
        }

    } catch (SMTPConnectionClosedException ex) {
        this.done();
        this.fault("Cannot add recipient.  Connection expired and closed itself.");
    } catch (Exception ex) {
        this.done();
        this.fault("Cannot add recipient due to exception.  message=" + ex.getMessage());
    } finally {
        this.done();
    }
}

From source file:autohit.call.modules.TolerantSmtpModule.java

/**
 * Login method. It will fault if a session has not been started or has
 * expired. The hostname is optional; pass null if not used.
 * /* w  w  w  .j  av  a2 s . c  om*/
 * @param hostname
 *            hostname to use instead of localhost.
 * @throws CallException
 */
private void login(String hostname) throws CallException {

    // Is it started?
    if (client == null) {
        this.error("Session not start()'ed.");
    }

    try {
        if (hostname == null) {
            client.login();
        } else {
            client.login(hostname);
        }

        // what happened?
        int code = client.getReplyCode();
        if (code >= SMTP_ERROR_THRESHOLD) {
            this.error("Login failed with code=" + code + " reply=" + client.getReplyString());
        } else {
            loggedIn = true;
            if (this.isDebugging()) {
                this.debug("Login complete.  code=" + code);
            }
        }

    } catch (SMTPConnectionClosedException ex) {
        this.done();
        this.error("Cannot login.  Connection expired and closed itself.");
    } catch (Exception ex) {
        this.done();
        this.error("Cannot login due to exception.  message=" + ex.getMessage());
    }
}

From source file:autohit.call.modules.TolerantSmtpModule.java

/**
 * Sender method. It will fault if a session has not been started or has
 * expired. It will set the sender. Subsequent calls will overwrite the
 * value. The address should be a valid email address.
 * /*from   w  w w. j  ava 2  s  .c  o  m*/
 * @param hostname
 *            hostname to use instead of localhost.
 * @throws CallException
 */
private void sender(String s) throws CallException {

    // Is it started?
    if (client == null) {
        this.error("Session not start()'ed.");
    }

    try {
        client.setSender(s);

        // what happened?
        int code = client.getReplyCode();
        if (code >= SMTP_ERROR_THRESHOLD) {
            this.error("Sender failed with code=" + code + " reply=" + client.getReplyString());
        } else if (this.isDebugging()) {
            this.debug("Sender complete.  code=" + code);
        }

    } catch (SMTPConnectionClosedException ex) {
        this.done();
        this.error("Cannot set sender.  Connection expired and closed itself.");
    } catch (Exception ex) {
        this.done();
        this.error("Cannot set sender due to exception.  message=" + ex.getMessage());
    }
}

From source file:autohit.call.modules.TolerantSmtpModule.java

/**
 * Recipient method. It will fault if a session has not been started or has
 * expired. It will add a recipient. Subsequent calls will add to the list
 * of recipients. The address should be a valid email address. The only way
 * to clear the list is to call reset() and start over.
 * // w w  w  . jav  a 2  s. co  m
 * @param hostname
 *            hostname to use instead of localhost.
 * @throws CallException
 */
private void recipient(String s) throws CallException {

    // Is it started?
    if (client == null) {
        this.error("Session not start()'ed.");
    }

    try {
        client.addRecipient(s);

        // what happened?
        int code = client.getReplyCode();
        if (code >= SMTP_ERROR_THRESHOLD) {
            this.error("Add recipient failed with code=" + code + " reply=" + client.getReplyString());
        } else if (this.isDebugging()) {
            this.debug("Add recipient complete.  code=" + code);
        }

    } catch (SMTPConnectionClosedException ex) {
        this.done();
        this.error("Cannot add recipient.  Connection expired and closed itself.");
    } catch (Exception ex) {
        this.done();
        this.error("Cannot add recipient due to exception.  message=" + ex.getMessage());
    }
}

From source file:autohit.call.modules.TolerantSmtpModule.java

/**
 * Sender relay method. It will fault if a session has not been started or
 * has expired. It will set the sender as the accumulated relay. You must
 * have called addsenderrelay() at least once or you will get an error.
 * Subsequent calls will overwrite the value.
 * //from  w w w.  j a  v  a  2  s .  c o  m
 * @param hostname
 *            hostname to use instead of localhost.
 * @throws CallException
 */
private void senderrelay() throws CallException {

    // Is it started?
    if (client == null) {
        this.error("Session not start()'ed.");
    }

    // Is there a relay?
    if (senderrelay == null) {
        this.error(
                "Sender relay not ready.  You need to call addsenderrelay() at least once before this method.");
        return;
    }

    try {
        client.setSender(senderrelay);

        // what happened?
        int code = client.getReplyCode();
        if (code >= SMTP_ERROR_THRESHOLD) {
            this.error("Set sender relay failed with code=" + code + " reply=" + client.getReplyString());
        } else if (this.isDebugging()) {
            this.debug("Set sender relay complete.  code=" + code);
        }

    } catch (SMTPConnectionClosedException ex) {
        this.done();
        this.error("Cannot set sender.  Connection expired and closed itself.");
    } catch (Exception ex) {
        this.done();
        this.error("Cannot set sender due to exception.  message=" + ex.getMessage());
    }
}