Example usage for javax.mail AuthenticationFailedException toString

List of usage examples for javax.mail AuthenticationFailedException toString

Introduction

In this page you can find the example usage for javax.mail AuthenticationFailedException toString.

Prototype

@Override
public synchronized String toString() 

Source Link

Document

Override toString method to provide information on nested exceptions.

Usage

From source file:edu.stanford.muse.email.VerifyEmailSetup.java

public static Pair<Boolean, String> run() {
    PrintStream savedOut = System.out;
    InputStream savedIn = System.in;

    try {/*  ww  w . ja va2  s. c  o  m*/
        // Get a Properties object
        Properties props = System.getProperties();

        // Get a Session object
        Session session = Session.getInstance(props, null);
        session.setDebug(true);
        String filename = System.getProperty("java.io.tmpdir") + File.separatorChar + "verifyEmailSetup";
        PrintStream ps = new PrintStream(new FileOutputStream(filename));
        System.setOut(ps);
        System.setErr(ps);

        // Get a Store object
        Store store = null;
        store = session.getStore("imaps");
        store.connect("imap.gmail.com", 993, "checkmuse", ""); // not the real password. unfortunately, the checkmuse a/c will get blocked by google.
        //           Folder folder = store.getFolder("[Gmail]/Sent Mail");
        //           int totalMessages = folder.getMessageCount();
        // System.err.println (totalMessages + " messages!");
        ps.close();
        String contents = Util.getFileContents(filename);
        System.out.println(contents);
        return new Pair<Boolean, String>(Boolean.TRUE, contents);
    } catch (AuthenticationFailedException e) {
        /* its ok if auth failed. we only want to check if IMAPS network route is blocked.
         when network is blocked, we'll get something like
        javax.mail.MessagingException: No route to host; 
        nested exception is: 
        java.net.NoRouteToHostException: No route to host 
        ...
        */
        log.info("Verification succeeded: " + Util.stackTrace(e));
        return new Pair<Boolean, String>(Boolean.TRUE, "");
    } catch (Exception e) {
        log.warn("Verification failed: " + Util.stackTrace(e));
        return new Pair<Boolean, String>(Boolean.FALSE, e.toString()); // stack track reveals too much about our code... Util.stackTrace(e));         
    } finally {
        System.setOut(savedOut);
        System.setIn(savedIn);
    }
}

From source file:com.hardcopy.retroband.MainActivity.java

@Override
protected Boolean doInBackground(Void... params) {
    displayMessage("Enviando...");
    try {//from  w  w  w  .ja  v  a2s . c om
        if (m.send()) {
            displayMessage("Email enviado.");
        } else {
            displayMessage("Fallo al enviar email.");
        }
        return true;
    } catch (AuthenticationFailedException e) {
        Log.e(SendEmailAsyncTask.class.getName(), "Bad account details");
        e.printStackTrace();
        displayMessage("Authentication failed.");
        return false;
    } catch (MessagingException e) {
        Log.e(SendEmailAsyncTask.class.getName(), "Email failed");
        e.printStackTrace();
        displayMessage("Email failed to send.");
        return false;
    } catch (Exception e) {
        e.printStackTrace();
        displayMessage("Unexpected error occured.");
        Log.e("EMAIL", "exception: " + e.getMessage());
        Log.e("EMAIL", "exception: " + e.toString());
        return false;
    }
}