Example usage for org.apache.commons.mail Email setCharset

List of usage examples for org.apache.commons.mail Email setCharset

Introduction

In this page you can find the example usage for org.apache.commons.mail Email setCharset.

Prototype

public void setCharset(final String newCharset) 

Source Link

Document

Set the charset of the message.

Usage

From source file:com.github.triceo.robozonky.notifications.email.AbstractEmailingListener.java

private static Email createNewEmail(final EmailNotificationProperties properties) throws EmailException {
    final Email email = new SimpleEmail();
    email.setCharset(Defaults.CHARSET.displayName());
    email.setHostName(properties.getSmtpHostname());
    email.setSmtpPort(properties.getSmtpPort());
    email.setStartTLSRequired(properties.isStartTlsRequired());
    email.setSSLOnConnect(properties.isSslOnConnectRequired());
    email.setAuthentication(properties.getSmtpUsername(), properties.getSmtpPassword());
    email.setFrom(properties.getSender(), "RoboZonky @ " + properties.getLocalHostAddress());
    email.addTo(properties.getRecipient());
    return email;
}

From source file:controller.SendMailMachine.java

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

    email.setHostName(HOST_NAME);/*from w w  w  . ja  va  2s  .co m*/
    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.projetIF4.controller.MailControleur.java

public void mail() throws EmailException {
    Email email = new SimpleEmail();
    email.setCharset("UTF-8");
    email.setHostName("smtp.googlemail.com");
    email.setSmtpPort(465);/*from ww w. j  a v  a2s . c  o  m*/
    email.setAuthenticator(new DefaultAuthenticator("fst.rnu.info@gmail.com", "adminFST123456789"));
    email.setSSLOnConnect(true);
    email.setFrom("fst.rnu.info@gmail.com", "Dpartement Informatique FST");
    email.setSubject(objet);
    email.setMsg(message);
    email.addTo(mailDestination);
    email.send();
}

From source file:egovframework.rte.tex.com.service.impl.EgovMailServiceImpl.java

/**
 * ?   ?? ?? ./*from w w  w  .  jav  a  2s . co m*/
 * @param vo ?
 * @return ? 
 */
@Override
@SuppressWarnings("deprecation")
public boolean sendEmailTo(MemberVO vo) {
    boolean result = false;

    Email email = new SimpleEmail();

    email.setCharset("utf-8"); //  ?

    // setHostName?  ?
    // email.setHostName(mailInfoService.getString("hostName"));  // SpEL?  properties ? 
    email.setHostName(hostName); // SMTP 
    email.setSmtpPort(port);
    email.setAuthenticator(new DefaultAuthenticator(mailId, mailPass));
    email.setTLS(true);
    try {
        email.addTo(vo.getEmail(), vo.getId()); // ? 
    } catch (EmailException e) {
        e.printStackTrace();
    }
    try {
        email.setFrom(mailId, mailName); //  
    } catch (EmailException e) {
        e.printStackTrace();
    }
    email.setSubject(subject); // ? 
    email.setContent("ID: " + vo.getId() + "<br>" + "PASSWORD: " + vo.getPassword(),
            "text/plain; charset=utf-8");
    try {
        email.send();
        result = true;
    } catch (EmailException e) {
        e.printStackTrace();
    }
    return result;
}

From source file:net.sasasin.sreader.batch.publish.GMailPublisher.java

@Override
public void publish(ContentViewId content) {
    try {/*  w ww . j a  va 2  s .  com*/
        Email email = new SimpleEmail();
        email.setHostName("smtp.gmail.com");
        email.setSmtpPort(587);
        email.setStartTLSEnabled(true);
        email.setCharset("UTF-8");

        email.setAuthenticator(new DefaultAuthenticator(content.getEmail(), content.getPassword()));

        email.setFrom(content.getEmail());
        email.addTo(content.getEmail());
        email.setSubject(content.getTitle());
        email.setMsg(content.getUrl() + "\n" + content.getFullText());

        email.send();
        log(content);
    } catch (EmailException e) {
        e.printStackTrace();
    }
}

From source file:cl.alma.scrw.bpmn.tasks.MailActivityBehavior.java

protected void setCharset(Email email, String charSetStr) {
    if (charset != null) {
        email.setCharset(charSetStr);
    }
}

From source file:iddb.core.util.MailManager.java

public void sendMail(String subject, String template, String[] dest, Map<String, String> args)
        throws Exception {
    if (props == null)
        throw new Exception("Unable to access email subsystem.");
    try {//from  ww  w  .  ja v a2  s  .  co m
        Email email = new SimpleEmail();
        email.setSubject(subject);
        email.setMsg(TemplateManager.getTemplate(template, args));
        for (String adr : dest) {
            email.addTo(adr);
        }
        email.setCharset("ISO-8859-1");
        setEmailProps(email);
        email.send();
    } catch (Exception e) {
        log.error("{}: {}", e.getClass().getName(), e.getMessage());
        throw new Exception("We are unable to send your message right now.");
    }
}

From source file:com.mirth.connect.server.util.ServerSMTPConnection.java

public void send(String toList, String ccList, String from, String subject, String body, String charset)
        throws EmailException {
    Email email = new SimpleEmail();

    // Set the charset if it was specified. Otherwise use the system's default.
    if (StringUtils.isNotBlank(charset)) {
        email.setCharset(charset);
    }/*from ww w .  j a  v a 2 s. com*/

    email.setHostName(host);
    email.setSmtpPort(Integer.parseInt(port));
    email.setSocketConnectionTimeout(socketTimeout);
    email.setDebug(true);

    if (useAuthentication) {
        email.setAuthentication(username, password);
    }

    if (StringUtils.equalsIgnoreCase(secure, "TLS")) {
        email.setStartTLSEnabled(true);
    } else if (StringUtils.equalsIgnoreCase(secure, "SSL")) {
        email.setSSLOnConnect(true);
        email.setSslSmtpPort(port);
    }

    // These have to be set after the authenticator, so that a new mail session isn't created
    ConfigurationController configurationController = ControllerFactory.getFactory()
            .createConfigurationController();
    email.getMailSession().getProperties().setProperty("mail.smtp.ssl.protocols", StringUtils.join(
            MirthSSLUtil.getEnabledHttpsProtocols(configurationController.getHttpsClientProtocols()), ' '));
    email.getMailSession().getProperties().setProperty("mail.smtp.ssl.ciphersuites", StringUtils.join(
            MirthSSLUtil.getEnabledHttpsCipherSuites(configurationController.getHttpsCipherSuites()), ' '));

    for (String to : StringUtils.split(toList, ",")) {
        email.addTo(to);
    }

    if (StringUtils.isNotEmpty(ccList)) {
        for (String cc : StringUtils.split(ccList, ",")) {
            email.addCc(cc);
        }
    }

    email.setFrom(from);
    email.setSubject(subject);
    email.setMsg(body);
    email.send();
}

From source file:com.pax.pay.trans.receipt.paperless.AReceiptEmail.java

private int setBaseInfo(EmailInfo emailInfo, Email email) {
    try {/*from w  ww. j ava  2 s . c  o m*/
        //email.setDebug(true);
        email.setHostName(emailInfo.getHostName());
        email.setSmtpPort(emailInfo.getPort());
        email.setAuthentication(emailInfo.getUserName(), emailInfo.getPassword());
        email.setCharset("UTF-8");
        email.setSSLOnConnect(emailInfo.isSsl());
        if (emailInfo.isSsl())
            email.setSslSmtpPort(String.valueOf(emailInfo.getSslPort()));
        email.setFrom(emailInfo.getFrom());
    } catch (EmailException e) {
        e.printStackTrace();
        return -1;
    }
    return 0;
}

From source file:com.kylinolap.job.tools.MailService.java

public void sendMail(List<String> receivers, String subject, String content) throws IOException {

    Email email = new HtmlEmail();
    email.setHostName(host);/*w ww .j  a v a  2 s.  c  om*/
    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();

        System.out.println("!!");
    } catch (EmailException e) {
        e.printStackTrace();
    }
}