Example usage for org.apache.commons.mail EmailException printStackTrace

List of usage examples for org.apache.commons.mail EmailException printStackTrace

Introduction

In this page you can find the example usage for org.apache.commons.mail EmailException printStackTrace.

Prototype

@Override
public void printStackTrace() 

Source Link

Document

Prints the stack trace of this exception to the standard error stream.

Usage

From source file:br.fgv.util.EmailSender.java

public static void main(String[] args) {
    try {//from w  ww  . j  a va2 s. c om
        enviarEmail("Mais um teste !", "Falha no sistema.");
    } catch (EmailException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.smi.travel.controller.mail.SendMail.java

public static void main(String args[]) throws Exception {
    EmailAttachment attachment = new EmailAttachment();
    HtmlEmail email = new HtmlEmail();
    try {/*w ww.j  av  a  2s.  c  o  m*/
        //            attachment.setPath("C:\\Users\\chonnasith\\Desktop\\test.txt");
        //            attachment.setDescription("file attachment");
        //            attachment.setName("test.txt");
        //            email.attach(attachment);
        email.setHostName(hostname);
        email.setSmtpPort(port);
        email.setAuthentication(username, password);
        email.setSSLOnConnect(true);
        //            email.setStartTLSEnabled(true);
        //            email.setStartTLSRequired(true);
        email.setFrom(username);
        email.setSubject(subject);
        email.addTo(addto);
        email.setHtmlMsg(message);
        email.send();
        System.out.println("Email Send");
        System.out.println("Port : " + email.getSmtpPort());
    } catch (EmailException ex) {
        System.out.println("Email Exception");
        System.out.println("Port : " + email.getSmtpPort());
        ex.printStackTrace();
    }

    //        InetAddress host = InetAddress.getByName("mail.foobar.com");
    //        System.out.println("host.isReachable(1000) = " + host.isReachable(1000));

    //        int port = 587;
    //        String host = "smtp.gmail.com";
    //        String user = "username@gmail.com";
    //        String pwd = "email password";
    //
    //        try {
    //            Properties props = new Properties();
    //            // required for gmail 
    //            props.put("mail.smtp.starttls.enable","true");
    //            props.put("mail.smtp.auth", "true");
    //            // or use getDefaultInstance instance if desired...
    //            Session session = Session.getInstance(props, null);
    //            Transport transport = session.getTransport("smtp");
    //            transport.connect(host, port, user, pwd);
    //            transport.close();
    //            System.out.println("success");
    //         } 
    //         catch(AuthenticationFailedException e) {
    //               System.out.println("AuthenticationFailedException - for authentication failures");
    //               e.printStackTrace();
    //         }
    //         catch(MessagingException e) {
    //               System.out.println("for other failures");
    //               e.printStackTrace();
    //         }

    //        Properties prop=new Properties();
    //        prop.put("mail.smtp.auth", "true");
    //        prop.put("mail.smtp.host", "smtp.gmail.com");
    //        prop.put("mail.smtp.port", "587");
    //        prop.put("mail.smtp.starttls.enable", "true");
    //
    //        Session session = Session.getDefaultInstance(prop,
    //        new javax.mail.Authenticator() {
    //            protected PasswordAuthentication getPasswordAuthentication() {
    //                return new PasswordAuthentication("finance@wendytour", "wendytr");
    //          }
    //        });
    //        
    //        try {
    //            String body="Dear Renish Khunt Welcome";
    //            String htmlBody = "<strong>This is an HTML Message</strong>";
    //            String textBody = "This is a Text Message.";
    //            Message message = new MimeMessage(session);
    //            message.setFrom(new InternetAddress(username));
    //            message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(addto));
    //            message.setSubject("Testing Subject");
    //            MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
    //            mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
    //            mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
    //            mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
    //            mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
    //            mc.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822");
    //            CommandMap.setDefaultCommandMap(mc);
    //            message.setText(htmlBody);
    //            message.setContent(textBody, "text/html");
    //            Transport.send(message);
    //
    //            System.out.println("Done");
    //
    //        } catch (MessagingException e) {
    //            e.printStackTrace();
    //        }

    //        final String fromEmail = "finance@wendytour"; //requires valid gmail id
    //        final String password = "wendytr"; // correct password for gmail id
    //        final String toEmail = "wee.chonnasith@gmail.com"; // can be any email id 
    //         
    //        System.out.println("TLSEmail Start");
    //        Properties props = new Properties();
    //        props.put("mail.smtp.host", ""); //SMTP Host
    //        props.put("mail.smtp.port", "587"); //TLS Port
    //        props.put("mail.smtp.auth", "true"); //enable authentication
    //        props.put("mail.smtp.starttls.enable", "true"); //enable STARTTLS
    //         
    //                //create Authenticator object to pass in Session.getInstance argument
    //        Authenticator auth = new Authenticator() {
    //            //override the getPasswordAuthentication method
    //            protected PasswordAuthentication getPasswordAuthentication() {
    //                return new PasswordAuthentication(fromEmail, password);
    //            }
    //        };
    //        Session session = Session.getInstance(props, auth);
    //         
    //        EmailUtil.sendEmail(session, toEmail,"TLSEmail Testing Subject", "TLSEmail Testing Body");
    //         

}

From source file:at.tugraz.kmi.medokyservice.ErrorLogNotifier.java

public static void errorEmail(String msg) {

    Email email = new SimpleEmail();
    email.setHostName("something.com");
    email.setSmtpPort(465);//www .  j a va 2  s  .  co  m
    DefaultAuthenticator auth = new DefaultAuthenticator("username", "pwd");
    email.setAuthenticator(auth);
    email.setSSLOnConnect(true);
    try {
        email.setFrom("email address");
        email.setSubject("[MEDoKyService] Error");
        email.setMsg(msg);
        email.addTo("yourmail.com");
        email.send();
    } catch (EmailException e) {
        e.printStackTrace();
    }

}

From source file:controller.SendMailMachine.java

public static void sendMail(Cart cart, String recipientEmail) {
    Email email = new SimpleEmail();

    email.setHostName(HOST_NAME);/*  w  ww .  j a  va2 s .  com*/
    email.setSmtpPort(465);
    email.setAuthenticator(new DefaultAuthenticator(EMAIL_SENDER, PASSWORD));
    email.setSSLOnConnect(true);

    String subject = "Thng tin ha n";
    String content = "\t\t\tTRUNG TM MUA SM BITTORRENT\n\nChi tit n hng ca bn: \n";
    for (Map.Entry<Integer, Item> entrySet : cart.getCartItem().entrySet()) {
        Item item = entrySet.getValue();
        content += item.getWatch().getName() + "\t\t\t\t\t\t" + item.getQuantity() + " x "
                + ((int) item.getWatch().getPrice()) + "000 VND\n";
    }
    content += "Tng ha n: " + ((int) cart.sumPrice()) + "000 VND";
    try {
        email.setFrom(EMAIL_SENDER);
        email.setCharset("UTF-8");
        email.setSubject(subject);
        email.setMsg(content);

        email.addTo(recipientEmail);

        email.send();
    } catch (EmailException ex) {

        ex.printStackTrace();
    }
}

From source file:com.github.somi92.seecsk.util.email.EmailSender.java

public static void sendEmail(EmailContainer ec) throws RuntimeException {

    try {/*from   www.  ja  v  a 2  s.c  om*/

        String user = Config.vratiInstancu().vratiVrednost(Constants.OrgInfoConfigKeys.ORGANISATION_EMAIL);
        String password = Config.vratiInstancu()
                .vratiVrednost(Constants.OrgInfoConfigKeys.ORGANISATION_EMAIL_PASSWORD);

        EmailAttachment ea = new EmailAttachment();
        ea.setPath(ec.getAttachmentPath());
        ea.setDisposition(EmailAttachment.ATTACHMENT);
        ea.setDescription("Primer ispravno popunjene uplatnice za ?lanarinu");
        ea.setName("uplatnica.pdf");

        MultiPartEmail mpe = new MultiPartEmail();
        mpe.setDebug(true);
        mpe.setAuthenticator(new DefaultAuthenticator(user, password));
        mpe.setHostName(
                Config.vratiInstancu().vratiVrednost(Constants.EmailServerConfigKeys.EMAIL_SERVER_HOST));
        mpe.setSSLOnConnect(true);
        mpe.setStartTLSEnabled(true);
        mpe.setSslSmtpPort(
                Config.vratiInstancu().vratiVrednost(Constants.EmailServerConfigKeys.EMAIL_SERVER_PORT));
        mpe.setSubject(ec.getSubject());
        mpe.setFrom(ec.getFromEmail(),
                Config.vratiInstancu().vratiVrednost(Constants.OrgInfoConfigKeys.ORGANISATION_NAME));
        mpe.setMsg(ec.getMessage());

        mpe.addTo(ec.getToEmail());
        mpe.attach(ea);

        mpe.send();

    } catch (EmailException ex) {
        ex.printStackTrace();
        throw new RuntimeException("Sistem nije uspeo da poalje email. Pokuajte ponovo.");
    }
}

From source file:br.com.dedoduro.util.EnviarEmail.java

/**
 * Enviar o email para a lista de usarios especificados
 * @param emails//from   w  w w  . j a va2s.  c  om
 * @param assunto
 * @param conteudo 
 */
private static void tratarEnvio(ArrayList<String> emails, String assunto, String conteudo) {
    HtmlEmail email = new HtmlEmail();

    try {
        email.setHostName(Constantes.HOST_NAME_GMAIL);
        email.addTo(Constantes.ADMINISTRADOR_1);
        email.setFrom(Constantes.EMAIL_REMETENTE_GMAIL, "Administrador");

        for (String tmp : emails) {
            email.addBcc(tmp);
        }

        email.setSubject(assunto);

        // Trabalhando com imagem...
        //            URL url = new URL ("http://<ENDERECO DA IMAGEM AQUI...>");
        //            String idImg = email.embed(url, "logo");

        email.setHtmlMsg(conteudo);

        // Tratando mensagem alternativa
        email.setTextMsg("Seu servidor de e-mail no suporta mensagem HTML... :-(");

        email.setSmtpPort(Constantes.PORTA_SMTP_GMAIL);
        email.setAuthenticator(
                new DefaultAuthenticator(Constantes.EMAIL_REMETENTE_GMAIL, Constantes.SENHA_REMETENTE_GMAIL));
        email.setSSLOnConnect(true);

        // Enviando email
        email.send();

    } catch (EmailException e) {
        e.printStackTrace();
    }
}

From source file:br.com.smarttaco.util.EnviarEmail.java

/**
 * Enviar o email para a lista de usarios especificados
 * @param emails/*from ww w  .  j  a  v a  2s .  c om*/
 * @param assunto
 * @param conteudo 
 */
public static void tratarEnvio(ArrayList<String> emails, String assunto, String conteudo) {
    HtmlEmail email = new HtmlEmail();

    try {
        email.setHostName(Constantes.HOST_NAME_GMAIL);
        email.addTo(Constantes.ADMINISTRADOR_1);
        email.setFrom(Constantes.EMAIL_REMETENTE_GMAIL, "SmartTaco - Administrador");

        for (String tmp : emails) {
            email.addBcc(tmp);
        }

        email.setSubject(assunto);

        // Trabalhando com imagem...
        //            URL url = new URL ("http://<ENDERECO DA IMAGEM AQUI...>");
        //            String idImg = email.embed(url, "logo");

        email.setHtmlMsg(conteudo);

        // Tratando mensagem alternativa
        email.setTextMsg("Seu servidor de e-mail no suporta mensagem HTML... :-(");

        email.setSmtpPort(Constantes.PORTA_SMTP_GMAIL);
        email.setAuthenticator(
                new DefaultAuthenticator(Constantes.EMAIL_REMETENTE_GMAIL, Constantes.SENHA_REMETENTE_GMAIL));
        email.setSSLOnConnect(true);

        // Enviando email
        email.send();

    } catch (EmailException e) {
        e.printStackTrace();
    }
}

From source file:controllers.PasswordResetApp.java

private static boolean sendPasswordResetMail(User user, String hashString) {
    Configuration config = play.Play.application().configuration();
    String sender = config.getString("smtp.user") + "@" + config.getString("smtp.domain");
    String resetPasswordUrl = getResetPasswordUrl(hashString);

    try {/* ww w .j  a  va2 s .c o m*/
        SimpleEmail email = new SimpleEmail();
        email.setFrom(sender)
                .setSubject(
                        "[" + utils.Config.getSiteName() + "] " + Messages.get("site.resetPasswordEmail.title"))
                .addTo(user.email)
                .setMsg(Messages.get("site.resetPasswordEmail.mailContents") + "\n\n" + resetPasswordUrl)
                .setCharset("utf-8");

        Logger.debug("password reset mail send: " + Mailer.send(email));
        return true;
    } catch (EmailException e) {
        e.printStackTrace();
        return false;
    }
}

From source file:controllers.CNAController.java

public static void generateGraph(ArrayList<Integer> bundles1, ArrayList<Integer> bundles2,
        ArrayList<Integer> bundles3, ArrayList<Integer> alterFactors, String epi, String showBundleNum)
        throws CNAException {
    try {//from  w ww.j  a  va  2  s . co m
        showBundleNumRenderer = (showBundleNum != null);
        makeEpi = (epi != null);
        RandomMTSetGenerator generator;
        ArrayList<ArrayList<Integer>> list;
        RandomMTGeneratorHelper input;

        list = new ArrayList<ArrayList<Integer>>();
        list.add(bundles1);
        list.add(bundles2);
        list.add(bundles3);

        input = new RandomMTGeneratorHelper(list, alterFactors, makeEpi);
        generator = new RandomMTSetGenerator(input.getCompleteList(), makeEpi);
        theories = generator.getMTSet();

        Graph graph = new Graph(theories);
        Renderer renderer = new Renderer();
        renderer.setShowEdgeLabels(showBundleNumRenderer);
        renderer.config(graph);

        String generatedGraphSource = renderer.getImageSource();
        String generatedGraphString = theories.toString();
        boolean calc = (theories.getAllNames().size() <= NUMFACTORS);
        if (!calc) {
            int allowed = NUMFACTORS - 1;
            flash.error("Only up to " + allowed + " factors allowed.");
            params.flash();
        }
        MTSetToTable parser = new MTSetToTable(theories);
        CNATable table = parser.getCoincTable();
        String coincTable = table.toString();
        render(calc, generatedGraphSource, generatedGraphString, coincTable);
    } catch (CNAException e) {
        flash.error(e.toString());
        params.flash();
        setup();
    } catch (IllegalArgumentException e) {
        flash.error(
                "All minimal theories have zero factors. Please specifiy the number of factors and bundles.");
        params.flash();
        setup();
    } catch (IndexOutOfBoundsException e) {
        try {
            SimpleEmail email = new SimpleEmail();
            email.setFrom(MAILFrom);
            email.addTo(MAILTo);
            email.setSubject("Error: IndexOutOfBoundsException");
            String msg = e.getStackTrace().toString();
            email.setMsg("CNA Random Gen\n" + msg);
            Mail.send(email);
        } catch (EmailException e1) {
            e1.printStackTrace();
        }
        flash.error("Something went wrong. Please try again or contact us.");
        params.flash();
        setup();
    } catch (OutOfMemoryError e) {
        flash.error("Server is out of memory, please wait a minute.");
        params.flash();
        setup();
    }
}

From source file:controllers.CNAController.java

public static void inputMT(String mtset) {
    try {//w  w w  .  java2s.c om
        CNAList list = new CNAList("\r\n", mtset);
        CNAList factors;
        theories = new MinimalTheorySet();
        MinimalTheory theorie;
        for (String str : list) {
            factors = new CNAList();
            String[] array = str.split("\\<=\\>");
            String[] fac = array[0].split("v");
            for (int i = 0; i < fac.length; i++) {
                factors.add(fac[i]);
            }
            if (array[1].length() > 1) {
                flash.error("Please insert as effect only a positive and only one factor.");
                params.flash();
                setup();
            }
            theorie = new MinimalTheory(factors, array[1]);
            theories.add(theorie);
        }
        for (MinimalTheory theory : theories) {
            if (theory.getBundleFactors().size() < 2) {
                flash.error(
                        "Violation of Minimal Diversity pre-condition: Every MT must have at least two bundles, alternate factors, or a bundle and a alternate factor.");
                params.flash();
                setup();
            }
        }
        Graph graph = new Graph(theories);
        Renderer renderer = new Renderer();
        renderer.setShowEdgeLabels(showBundleNumRenderer);
        renderer.config(graph);

        String generatedGraphSource = renderer.getImageSource();
        String generatedGraphString = theories.toString();
        boolean calc = (theories.getAllNames().size() <= NUMFACTORS);
        if (!calc) {
            flash.error("Only up to " + NUMFACTORS + " factors allowed.");
            params.flash();
        }
        MTSetToTable parser;
        try {
            parser = new MTSetToTable(theories);
            CNATable table = parser.getCoincTable();
            String coincTable = table.toString();
            render(generatedGraphSource, generatedGraphString, calc, coincTable);
        } catch (CNAException e) {
            flash.error("Something went wrong. Please try again or contact us.");
            params.flash();
            setup();
        }
    } catch (OutOfMemoryError e) {
        flash.error("Server is out of memory, please wait a minute.");
        params.flash();
        setup();
    } catch (ArrayIndexOutOfBoundsException e) {
        flash.error("You're input is not according to our syntax. Please correct it.");
        params.flash();
        setup();
    } catch (IndexOutOfBoundsException e) {
        try {
            SimpleEmail email = new SimpleEmail();
            email.setFrom(MAILFrom);
            email.addTo(MAILTo);
            email.setSubject("Error: IllegalArgumentException");
            String msg = e.getStackTrace().toString();
            email.setMsg("CNA Input MT\n" + msg);
            Mail.send(email);
        } catch (EmailException e1) {
            e1.printStackTrace();
        }
        flash.error("Something went wrong. Please try again or contact us.");
        params.flash();
        setup();
    } catch (IllegalArgumentException e) {
        try {
            SimpleEmail email = new SimpleEmail();
            email.setFrom(MAILFrom);
            email.addTo(MAILFrom);
            email.setSubject("Error: IllegalArgumentException");
            String msg = e.getStackTrace().toString();
            email.setMsg("CNA Input MT\n" + msg);
            Mail.send(email);
        } catch (EmailException e1) {
            e1.printStackTrace();
        }
        flash.error("Something went wrong. Please try again or contact us.");
        params.flash();
        setup();
    }
}