List of usage examples for org.apache.commons.mail HtmlEmail setCharset
public void setCharset(final String newCharset)
From source file:org.vulpe.commons.util.VulpeEmailUtil.java
/** * Send Mail to many recipients./*w w w . j a v a2 s .co m*/ * * @param recipients * Recipients * @param subject * Subject * @param body * Body * @throws VulpeSystemException * exception */ public static boolean sendMail(final String[] recipients, final String subject, final String body) { boolean sended = true; if (!checkValidEmail(recipients)) { LOG.error("Invalid mails: " + recipients); sended = false; } if (isDebugEnabled) { LOG.debug("Entering in sendMail..."); for (int i = 0; i < recipients.length; i++) { LOG.debug("recipient: " + recipients[i]); } LOG.debug("subject: " + subject); LOG.debug("body: " + body); } try { final ResourceBundle bundle = ResourceBundle.getBundle("mail"); if (bundle != null) { final HtmlEmail mail = new HtmlEmail(); String mailFrom = ""; if (bundle.containsKey("mail.smtp.auth") && Boolean.valueOf(bundle.getString("mail.smtp.auth"))) { final String username = bundle.getString("mail.smtp.user"); final String password = bundle.getString("mail.smtp.password"); mail.setAuthentication(username, password); } if (bundle.containsKey("mail.from")) { mailFrom = bundle.getString("mail.from"); } mail.setFrom(mailFrom); for (final String recipient : recipients) { mail.addTo(recipient); } mail.setHostName(bundle.getString("mail.smtp.host")); final String port = bundle.getString("mail.smtp.port"); mail.setSmtpPort(Integer.valueOf(port)); if (bundle.containsKey("mail.smtp.starttls.enable") && Boolean.valueOf(bundle.getString("mail.smtp.starttls.enable"))) { mail.setTLS(true); mail.setSSL(true); if (bundle.containsKey("mail.smtp.socketFactory.port")) { String factoryPort = bundle.getString("mail.smtp.socketFactory.port"); mail.setSslSmtpPort(factoryPort); } } String encoding = "UTF-8"; if (bundle.containsKey("mail.encode")) { encoding = bundle.getString("mail.encode"); } mail.setCharset(encoding); mail.setSubject(subject); mail.setHtmlMsg(body); mail.send(); } else { LOG.error("Send Mail properties not setted"); sended = false; } } catch (Exception e) { LOG.error("Error on send mail", e); sended = false; } LOG.debug("Out of sendMail..."); return sended; }
From source file:velo.tools.EdmEmailSender.java
License:asdf
public Email factoryEmail(String subject, String body) throws EmailException { HtmlEmail he = new HtmlEmail(); he.setSubject(subject);/*ww w . j ava 2s. co m*/ he.setHtmlMsg(body); he.setCharset("UTF-8"); he.setHostName(getHostName()); he.setFrom(fromAddress); return he; }
From source file:velo.tools.EmailSender.java
public void addHtmlEmail(String fromAddress, Collection<String> recipient, String subject, String body) throws EmailException { HtmlEmail email = new HtmlEmail(); email.setHostName(getHostName());/* w ww .j a v a2 s.c o m*/ //email.addTo("jdoe@somewhere.org", "John Doe"); //email.addTo(recipient,recipient); email.setFrom(fromAddress, fromAddress); email.setSubject(subject); email.setHtmlMsg(body); for (String currRec : recipient) { email.addTo(currRec); } email.setCharset("UTF-8"); log.debug("Adding a new message with subject '" + subject + "', from: '" + fromAddress + "', to: '" + recipient + "' to the queue..."); log.debug("Email server parameters - SMTP host: " + getHostName()); emails.add(email); }