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

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

Introduction

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

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:jobs.Utils.java

public static void emailAdmin(String subject, String message) {

    SimpleEmail email = new SimpleEmail();
    try {/* w w  w  . j  a  va  2 s .  c  o  m*/
        email.setFrom("super.cool.bot@gmail.com");
        String address = (String) play.Play.configuration.get("mail.admin");
        email.addTo(address);
        email.setSubject(subject);
        email.setMsg(message);
        Mail.send(email);
    } catch (EmailException e) {
        Logger.error(e.getLocalizedMessage());
    }
}

From source file:com.kylinolap.common.util.MailService.java

/**
 * /*  w w  w. j a  v a 2  s . c o  m*/
 * @param receivers
 * @param subject
 * @param content
 * @return true or false indicating whether the email was delivered successfully
 * @throws IOException
 */
public boolean sendMail(List<String> receivers, String subject, String content) throws IOException {

    if (!enabled) {
        logger.info("Email service is disabled; this mail will not be delivered: " + subject);
        logger.info("To enable mail service, set 'mail.enabled=true' in kylin.properties");
        return false;
    }

    Email email = new HtmlEmail();
    email.setHostName(host);
    if (username != null && username.trim().length() > 0) {
        email.setAuthentication(username, password);
    }

    //email.setDebug(true);
    try {
        for (String receiver : receivers) {
            email.addTo(receiver);
        }

        email.setFrom(sender);
        email.setSubject(subject);
        email.setCharset("UTF-8");
        ((HtmlEmail) email).setHtmlMsg(content);
        email.send();
        email.getMailSession();

    } catch (EmailException e) {
        logger.error(e.getLocalizedMessage(), e);
        return false;
    }

    return true;
}

From source file:org.apache.kylin.common.util.MailService.java

/**
 * @param receivers/* w w w  .  ja  v a  2 s.c o  m*/
 * @param subject
 * @param content
 * @return true or false indicating whether the email was delivered successfully
 * @throws IOException
 */
public boolean sendMail(List<String> receivers, String subject, String content, boolean isHtmlMsg) {

    if (!enabled) {
        logger.info("Email service is disabled; this mail will not be delivered: " + subject);
        logger.info("To enable mail service, set 'kylin.job.notification-enabled=true' in kylin.properties");
        return false;
    }

    Email email = new HtmlEmail();
    email.setHostName(host);
    email.setStartTLSEnabled(starttlsEnabled);
    if (starttlsEnabled) {
        email.setSslSmtpPort(port);
    } else {
        email.setSmtpPort(Integer.valueOf(port));
    }

    if (username != null && username.trim().length() > 0) {
        email.setAuthentication(username, password);
    }

    //email.setDebug(true);
    try {
        for (String receiver : receivers) {
            email.addTo(receiver);
        }

        email.setFrom(sender);
        email.setSubject(subject);
        email.setCharset("UTF-8");
        if (isHtmlMsg) {
            ((HtmlEmail) email).setHtmlMsg(content);
        } else {
            ((HtmlEmail) email).setTextMsg(content);
        }
        email.send();
        email.getMailSession();

    } catch (EmailException e) {
        logger.error(e.getLocalizedMessage(), e);
        return false;
    }

    return true;
}

From source file:org.chenillekit.mail.services.impl.MailServiceImpl.java

/**
 * send an email.//  w w w .  ja  v a  2s  .  c o  m
 */
public boolean sendEmail(Email email) {
    boolean sended = true;

    try {
        //         email.setHostName(smtpServer);
        //
        //         if (smtpUser != null && smtpUser.length() > 0)
        //            email.setAuthentication(smtpUser, smtpPassword);
        //
        //         email.setDebug(smtpDebug);
        //         email.setSmtpPort(smtpPort);
        //         email.setSSL(smtpSSL);
        //         email.setSslSmtpPort(String.valueOf(smtpSslPort));
        //         email.setTLS(smtpTLS);

        setEmailStandardData(email);

        email.send();
    } catch (EmailException e) {
        logger.error(e.getLocalizedMessage(), e);
        sended = false;
    }

    return sended;
}

From source file:org.opencms.notification.CmsNotificationCandidates.java

/**
 * Sends all notifications to the responsible users.<p>
 * /*from w  w w.j  a  va 2  s.  co  m*/
 * @return a string listing all responsibles that a notification was sent to
 * 
 * @throws CmsException if something goes wrong
 */
public String notifyResponsibles() throws CmsException {

    Iterator notifications = filterConfirmedResources(getContentNotifications()).iterator();
    if (notifications.hasNext()) {
        StringBuffer result = new StringBuffer(
                Messages.get().getBundle().key(Messages.LOG_NOTIFICATIONS_SENT_TO_0));
        result.append(' ');
        while (notifications.hasNext()) {
            CmsContentNotification contentNotification = (CmsContentNotification) notifications.next();
            result.append(contentNotification.getResponsible().getName());
            if (notifications.hasNext()) {
                result.append(", ");
            }
            try {
                contentNotification.send();
            } catch (EmailException e) {
                LOG.error(e.getLocalizedMessage(), e);
            }
        }
        return result.toString();
    } else {
        return Messages.get().getBundle().key(Messages.LOG_NO_NOTIFICATIONS_SENT_0);
    }
}

From source file:org.polymap.rhei.um.operations.NewPasswordOperation.java

@Override
public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
    try {//from w  w w  .ja  v  a  2s .com
        // password hash
        PasswordEncryptor encryptor = PasswordEncryptor.instance();
        String password = encryptor.createPassword(8);
        String hash = encryptor.encryptPassword(password);
        user.passwordHash().set(hash);
        log.debug("Neues Passwort: " + password + " -> " + hash);

        // username <= email
        String username = user.email().get();
        assert username != null && username.length() > 0;
        user.username().set(username);
        log.info("username: " + user.username().get());

        // commit
        UserRepository.instance().commitChanges();

        // XXX email
        String salu = user.salutation().get() != null ? user.salutation().get() : "";
        String header = (salu.equalsIgnoreCase("Herr") ? "r Herr " : " ") + salu + " " + user.name().get();
        Email email = new SimpleEmail();
        email.setCharset("ISO-8859-1");
        email.addTo(username).setSubject(i18n.get("emailSubject"))
                .setMsg(i18n.get("email", header, username, password));

        EmailService.instance().send(email);

        return Status.OK_STATUS;
    } catch (EmailException e) {
        throw new ExecutionException(i18n.get("errorMsg", e.getLocalizedMessage()), e);
    }
}

From source file:org.polymap.rhei.um.operations.NewUserOperation.java

@Override
public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
    try {//from  ww  w.  j a  v  a  2s  .c o  m
        // password hash
        PasswordEncryptor encryptor = PasswordEncryptor.instance();
        String password = encryptor.createPassword(8);
        String hash = encryptor.encryptPassword(password);
        user.passwordHash().set(hash);

        // username <= email
        String username = user.email().get();
        assert username != null && username.length() > 0;
        user.username().set(username);
        log.info("username: " + user.username().get());

        // commit
        UserRepository.instance().commitChanges();

        String salu = user.salutation().get() != null ? user.salutation().get() : "";
        String header = (salu.equalsIgnoreCase("Herr") ? "r " : " ") + salu + " " + user.name().get();
        Email email = new SimpleEmail();
        email.setCharset("ISO-8859-1");
        email.addTo(username).setSubject(emailSubject)
                .setMsg(new MessageFormat(emailContent, Polymap.getSessionLocale())
                        .format(new Object[] { header, username, password }));
        //                    .setMsg( i18n.get( "email", header, username, password ) );

        EmailService.instance().send(email);

        return Status.OK_STATUS;

    } catch (EmailException e) {
        throw new ExecutionException(i18n.get("errorMsg", e.getLocalizedMessage()), e);
    }
}