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

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

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:ar.com.pahema.utils.MailSender.java

public static void enviar(String destino, Paquete paquete) throws EmailException {
    try {//w ww.  j a va2s.  c  o  m
        Email mail = new SimpleEmail();
        //Configuracion necesaria para GMAIL
        mail.setHostName("mail.pahema.com.ar");
        //mail.setTLS(true);
        mail.setSmtpPort(25);
        //mail.setSSL(true);
        //En esta seccion colocar cuenta de usuario de Gmail y contrasea
        mail.setAuthentication("dante@pahema.com.ar", "Fuerza2015");

        //Cuenta de Email Destino
        // AC? IRIA LA DE ADMINISTRACION DE PAHEMA. mail.addTo("dante.gs@hotmail.com");
        mail.addTo(destino);
        //Cuenta de Email Origen, la misma con la que nos autenticamos
        mail.setFrom("dante@pahema.com.ar", "Pahema - Sistema Tango");
        //Titulo del Email
        mail.setSubject("Aviso de finalizacin de paquete de horas.");
        //Contenido del Email
        mail.setMsg("Estimado cliente,\n" + "Le informamos que su paquete de "
                + (int) paquete.getCantidadHoras() + " horas est por finalizar.\n" + "Le quedan por usar: "
                + (int) paquete.getHorasRestantes() + " horas.\n"
                + "Por favor comunquese con Pahema para el detalle de sus consumos: 4952 - 4789.\n"
                + "Muchas gracias.\n" + "Administracin.");
        mail.send();
    } catch (EmailException e) {
        System.out.println(e.getMessage());
        throw new RuntimeException("Ocurrio un error en el envio del mail");
    }
}

From source file:model.Email.java

public static void sendToken(String receiver, String token) throws EmailException {

    SimpleEmail email = new SimpleEmail();
    String message = "Para sua segurana, voc precisa colocar o cdigo abaixo para continar a transao.\n";
    message += "Token: " + token + "\n";
    message += "\nO sistema de token  para sua segurana, sempre ao realizar uma transao, um novo token  gerado ";
    message += " e enviado  voc.";

    try {/* w  ww  .  jav a2s  . com*/
        email.setHostName("smtp.googlemail.com");
        email.setSmtpPort(465);
        email.setAuthenticator(new DefaultAuthenticator("totheworldgroup@gmail.com", "albrcalu"));
        email.setSSLOnConnect(true);
        email.setFrom("totheworldgroup@gmail.com");
        email.setSubject("Token para realizar transao");
        email.setMsg(message);
        email.addTo(receiver);
        email.send();

    } catch (EmailException e) {
        System.out.println(e.getMessage());
    }

}

From source file:model.Email.java

public static void sendConfirmation(String receiver, String token, PersonalAccount account)
        throws EmailException {

    SimpleEmail email = new SimpleEmail();
    String message = "Sua conta foi criada com sucesso, porm ainda est inativa.\n";
    message += "Nmero da conta: " + account.getNumber() + "\n";
    message += "Agncia: " + account.getAgency().getNumber() + "\n";
    message += "Token de autentificao: " + token + "\n";
    message += "Com este token voc  capaz de definir uma senha para sua conta para, ento, utiliz-la.\n";
    message += "\nCaso voc perca este token, entre novamente com as informaes para abrir conta,";
    message += " e um novo token ser gerado e reenviado  voc.";

    try {/*from   www.  j a  v a 2 s.co  m*/
        email.setHostName("smtp.googlemail.com");
        email.setSmtpPort(465);
        email.setAuthenticator(new DefaultAuthenticator("totheworldgroup@gmail.com", "albrcalu"));
        email.setSSLOnConnect(true);
        email.setFrom("totheworldgroup@gmail.com");
        email.setSubject("Token de autentificao");
        email.setMsg(message);
        email.addTo(receiver);
        email.send();

    } catch (EmailException e) {
        System.out.println(e.getMessage());
    }

}

From source file:gsn.utils.services.EmailService.java

/**
 * This method cover most of the cases of sending a simple text email. If the email to be sent has to be configured
 * in a way which is not possible whith the parameters provided (such as html email, or email with attachement, ..),
 * please use the {@link #sendCustomEmail(org.apache.commons.mail.Email)} method and refer the API
 * {@see http://commons.apache.org/email/}.
 *
 * @param to      A set of destination email address of the email. Must contain at least one address.
 * @param object  The subject of the email.
 * @param message The msg of the email./*from   w  w  w  . j  ava  2 s .c  o m*/
 * @return true if the email has been sent successfully, false otherwise.
 */
public static boolean sendEmail(ArrayList<String> to, String object, String message) {
    Email email = new SimpleEmail();
    try {
        email.setSubject(object);
        email.setMsg(message);
        if (to != null)
            for (String _to : to)
                email.addTo(_to);
        sendCustomEmail(email);
        return true;
    } catch (EmailException e) {
        logger.warn(
                "Please, make sure that the SMTP server configuration is correct in the file: " + SMTP_FILE);
        logger.error(e.getMessage(), e);
        return false;
    }
}

From source file:de.knurt.fam.core.util.mail.UserMailSender.java

/**
 * send an email without need to put it into the userbox (without saved in
 * database). put only smtp port and host to it as configured in
 * {@link UserMailSender}. do not change anything else but send the email!
 * /*from   www  .j a  v  a  2  s .  co m*/
 * @param raw
 *            all content (subject, msg, attachments, from, to) must be set
 * @return true if sending succeeded.
 */
public static boolean sendWithoutUserBox(Email raw) {
    boolean result = true;
    UserMailSender dse = getInstance();

    raw.setHostName(dse.hostName);
    raw.setSmtpPort(dse.smtpPort);

    if (FamConnector.isDev() == false) {
        try {
            raw.send();
        } catch (EmailException e) {
            result = false;
            FamLog.exception("sendWithoutUserBox: " + e.getMessage(), e, 201106131753l);
        }
    }
    if (result) {
        if (SEND_WITHOUT_METER == Integer.MAX_VALUE) {
            SEND_WITHOUT_METER = 0;
        }
        SEND_WITHOUT_METER++;
    }
    return result;
}

From source file:de.knurt.fam.core.util.mail.UserMailSender.java

private static boolean send(UserMail um) {
    boolean sendSucc = false;
    UserMailSender dse = getInstance();/*from  w w  w  .  ja  va2  s  .  c  o  m*/
    if (um.hasBeenSent() == false) {
        if (um.mustBeSendNow()) {
            // prepare
            SimpleEmail email = new SimpleEmail();
            email.setHostName(dse.hostName);
            email.setSmtpPort(dse.smtpPort);
            // mail server using pass
            if (dse.authName != null) {
                email.setAuthentication(dse.authName, dse.authPass);
            }
            Map<String, String> headers = new Hashtable<String, String>();
            // headers.put("Subject", um.getSubject());
            email.setSubject(um.getSubject());
            headers.put("Content-Type", "text/plain; charset=utf-8");
            headers.put("Content-Transfer-Encoding", "base64");
            email.setHeaders(headers);
            boolean creatingSucc = false;
            try {
                email.addTo(um.getTo(), um.getUsername());
                email.setFrom(dse.fromMail, dse.fromName);
                email.setMsg(um.getMsg());
                creatingSucc = true;
            } catch (EmailException ex) {
                FamLog.logException(UserMailSender.class, ex,
                        "creating mail failed::" + um.getTo() + "::" + um.getUsername() + "::" + um.getId(),
                        200904031116l);
            }

            if (creatingSucc && FamConnector.isDev() == false) {
                try {
                    email.send();
                    sendSucc = true;
                } catch (EmailException ex) {
                    FamLog.exception("sending a mail failed: " + ex.getMessage() + "-" + dse.fromMail + "-"
                            + dse.fromName, ex, 200904031018l);
                }
            } else { // just dev mode - do not send any mails
                sendSucc = true;
            }
        }
    } else {
        FamLog.logException(UserMailSender.class,
                new DataIntegrityViolationException("try to send a mail twice"), "try to send a mail twice",
                200908201836l);
    }
    return sendSucc;
}

From source file:dk.clarin.tools.workflow.java

public static void didnotget200(int code, String result, String endpoint, String requestString, bracmat BracMat,
        String filename, String jobID, boolean postmethod, String urlStr, String message,
        String requestResult) {//  w  ww.j ava  2  s . c o m
    String filelist;
    String mail2 = BracMat.Eval("mail2$(" + result + ")");
    logger.debug("Job " + jobID + " has mail2 '" + mail2 + "'");
    try {
        if (code == 202) {
            if (!mail2.equals("")) {
                //String toolsdataURL = BracMat.Eval("toolsdataURL$");
                sendMail(ACCEPT, "dig", "", "", "", mail2);
            }
            logger.warn("Got status code 202. Job " + jobID + " is set to wait for asynchronous result.");
            /**
              * waitingJob$
              *
              * Make a job 'waiting'.
              * 
              * Input: JobNr and jobID
              *
              * Affected tables in jboss/server/default/data/tools:
              *     jobs.table
              */
            BracMat.Eval("waitingJob$(" + result + "." + jobID + ")");
            //jobs = 0; // No more jobs to process now, quit from loop and wait for result to be sent
        } else if (code == 0) {
            //jobs = 0; // No more jobs to process now, probably the tool is not integrated at all
            filelist = BracMat.Eval("abortJob$(" + result + "." + jobID + ")");
            logger.warn("abortJob returns " + filelist);
            if (!mail2.equals("")) {
                //String toolsdataURL = BracMat.Eval("toolsdataURL$");

                sendMail(ERROR, "",
                        "endpoint:" + endpoint + " requestString:" + requestString + " filename:" + filename
                                + " jobID:" + jobID + " postmethod:" + (postmethod ? "y" : "n"),
                        "No more jobs to process now, probably the tool is not integrated at all", filelist,
                        ToolsProperties.admEmail);
                sendMail(ERRORUSER, "", "endpoint:" + endpoint, "probably the tool is not integrated at all",
                        filelist, mail2);
            }
            logger.warn("Job " + jobID + " cannot open connection to URL " + urlStr);
        } else {
            filelist = BracMat.Eval("abortJob$(" + result + "." + jobID + ")");
            logger.warn("abortJob returns " + filelist);
            if (!mail2.equals("")) {
                //String toolsdataURL = BracMat.Eval("toolsdataURL$");
                sendMail(ERROR, "",
                        "Clarin.dk har modtaget en statuskode " + code + " (" + message + ") fra " + endpoint
                                + ".<br />\n (Request:<br />\n" + requestString + ")<br /><br />\n\n",
                        requestResult, filelist, ToolsProperties.admEmail);

                sendMail(ERRORUSER, "",
                        "Clarin.dk har modtaget en statuskode som indikerer at der er sket en fejl: " + code
                                + " (" + message + ") fra " + endpoint + ".<br />\n<br /><br />\n\n",
                        requestResult, filelist, mail2);
            }
            logger.warn("Got status code [" + code + "]. Job " + jobID + " is aborted.");
        }
    } catch (org.apache.commons.mail.EmailException e) {
        logger.error("EmailException. Reason:" + e.getMessage());
    }
}

From source file:controllers.Send.java

public static Result sendTransactionViaEmail(String id, String recipient) {
    // Send email
    //      models.Customer sender = models.Customer.find.byId(transactionForm.get().sender.id);

    Logger.debug("Tyrying to send transaction to " + recipient);
    if (recipient == null) {
        // TODO get from beneficiary email
        flash("error", "Unidentified sender email");
    }/*  ww w. j  av a2s .  c o  m*/

    try {
        JsonNode result = ApiHelper.transactionDetail(id);
        Html html = receipt_email.render(result);

        InternetAddress[] tos = InternetAddress.parse(recipient);
        if ((tos.length > 0)) {
            InternetAddress to = tos[0];
            to.validate();
            //TODO Check if valid
            ApiHelper.sendHtmlEmail(null, tos[0], "Bukti transaksi pengiriman uang", html);
            flash("success", "Transaction email has been sent to sender email <strong>"
                    + recipient.replaceAll("<", "(").replaceAll(">", ")") + "</strong>");
        } else {
            //            flash("error", "Unable to send email to "+recipient);
        }
    } catch (EmailException e) {
        e.printStackTrace();
        Logger.error(e.getMessage(), e);
        flash("error", "Unable to send email to " + recipient);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        Logger.error(e.getMessage(), e);
        flash("error", "Unable to send email to " + recipient);
    } catch (AddressException e) {
        e.printStackTrace();
        Logger.error(e.getMessage(), e);
        flash("error", "Unable to send email to " + recipient);
    }

    return redirect(routes.Send.receipt(id));
}

From source file:ch.sbb.releasetrain.utils.emails.SMTPUtilImpl.java

@Override
public void send(String absender, String empfaenger, String betreff, String text) {
    try {/*  w  ww . java2 s  . c  o m*/
        final Email email = new SimpleEmail();
        email.setHostName(mailhost);
        email.setSmtpPort(mailport);
        email.setFrom(absender);
        email.setSubject(betreff);
        email.setMsg(text);
        email.addTo(empfaenger);
        email.send();
        log.info("mail sent to: " + empfaenger);
    } catch (final EmailException e) {
        log.error(e.getMessage(), e);
    }
}

From source file:dk.dma.ais.abnormal.analyzer.reports.ReportMailer.java

/**
 * Send email with subject and message body.
 * @param subject the email subject.//ww  w .  ja  va  2s  .  c o m
 * @param body the email body.
 */
public void send(String subject, String body) {
    try {
        HtmlEmail email = new HtmlEmail();
        email.setHostName(configuration.getString(CONFKEY_REPORTS_MAILER_SMTP_HOST, "localhost"));
        email.setSmtpPort(configuration.getInt(CONFKEY_REPORTS_MAILER_SMTP_PORT, 465));
        email.setAuthenticator(
                new DefaultAuthenticator(configuration.getString(CONFKEY_REPORTS_MAILER_SMTP_USER, "anonymous"),
                        configuration.getString(CONFKEY_REPORTS_MAILER_SMTP_PASS, "guest")));
        email.setStartTLSEnabled(false);
        email.setSSLOnConnect(configuration.getBoolean(CONFKEY_REPORTS_MAILER_SMTP_SSL, true));
        email.setFrom(configuration.getString(CONFKEY_REPORTS_MAILER_SMTP_FROM, ""));
        email.setSubject(subject);
        email.setHtmlMsg(body);
        String[] receivers = configuration.getStringArray(CONFKEY_REPORTS_MAILER_SMTP_TO);
        for (String receiver : receivers) {
            email.addTo(receiver);
        }
        email.send();
        LOG.info("Report sent with email to " + email.getToAddresses().toString() + " (\"" + subject + "\")");
    } catch (EmailException e) {
        LOG.error(e.getMessage(), e);
    }
}