List of usage examples for org.apache.commons.mail Email setReplyTo
public Email setReplyTo(final Collection<InternetAddress> aCollection) throws EmailException
From source file:fr.gael.dhus.messaging.mail.MailServer.java
public void send(Email email, String to, String cc, String bcc, String subject) throws EmailException { email.setHostName(getSmtpServer());//from www. ja v a2 s . c om email.setSmtpPort(getPort()); if (getUsername() != null) { email.setAuthentication(getUsername(), getPassword()); } if (getFromMail() != null) { if (getFromName() != null) email.setFrom(getFromMail(), getFromName()); else email.setFrom(getFromMail()); } if (getReplyto() != null) { try { email.setReplyTo(ImmutableList.of(new InternetAddress(getReplyto()))); } catch (AddressException e) { logger.error("Cannot configure Reply-to (" + getReplyto() + ") into the mail: " + e.getMessage()); } } // Message configuration email.setSubject("[" + cfgManager.getNameConfiguration().getShortName() + "] " + subject); email.addTo(to); // Add CCed if (cc != null) { email.addCc(cc); } // Add BCCed if (bcc != null) { email.addBcc(bcc); } email.setStartTLSEnabled(isTls()); try { email.send(); } catch (EmailException e) { logger.error("Cannot send email: " + e.getMessage()); throw e; } }
From source file:org.fao.geonet.util.MailUtil.java
/** * Send a plain text mail. Will look on the settings directly to know the * remitent/* ww w . j a v a2s.c o m*/ * * @param toAddress * @param subject * @param message * @param htmlMessage * @param settings * @param replyTo * @param replyToDesc @throws EmailException */ public static Boolean sendMail(List<String> toAddress, String subject, String message, String htmlMessage, SettingManager settings, String replyTo, String replyToDesc) { // Create data information to compose the mail boolean isHtml = StringUtils.isNotBlank(htmlMessage); Email email = isHtml ? new HtmlEmail() : new SimpleEmail(); configureBasics(settings, email); List<InternetAddress> addressColl = new ArrayList<InternetAddress>(); if (StringUtils.isNotEmpty(replyTo)) { try { addressColl.add(new InternetAddress(replyTo, replyToDesc)); email.setReplyTo(addressColl); } catch (UnsupportedEncodingException e2) { Log.error(LOG_MODULE_NAME, "Error setting email replyTo. Characters not supported in \"" + replyToDesc + "\"", e2); return false; } catch (EmailException e) { Log.error(LOG_MODULE_NAME, "Error setting email replyTo. Invalid email address \"" + replyTo + "\"", e); return false; } } email.setSubject(subject); try { if (StringUtils.isNotBlank(message)) { email.setMsg(message); } if (isHtml) { ((HtmlEmail) email).setHtmlMsg(htmlMessage); } } catch (EmailException e1) { Log.error(LOG_MODULE_NAME, "Error setting email message", e1); return false; } // send to all mails extracted from settings for (String add : toAddress) { try { email.addBcc(add); } catch (EmailException e) { Log.error(LOG_MODULE_NAME, "Error setting email BCC address " + add, e); } } return send(email); }
From source file:org.fao.geonet.util.MailUtil.java
public static void testSendMail(List<String> toAddress, String subject, String message, String htmlMessage, SettingManager settings, String replyTo, String replyToDesc) throws Exception { // Create data information to compose the mail boolean isHtml = StringUtils.isNotBlank(htmlMessage); Email email = isHtml ? new HtmlEmail() : new SimpleEmail(); configureBasics(settings, email);/*from w w w .j a va 2s . c o m*/ List<InternetAddress> addressColl = new ArrayList<InternetAddress>(); addressColl.add(new InternetAddress(replyTo, replyToDesc)); email.setReplyTo(addressColl); email.setSubject(subject); if (StringUtils.isNotBlank(message)) { email.setMsg(message); } if (isHtml) { ((HtmlEmail) email).setHtmlMsg(htmlMessage); } // send to all mails extracted from settings for (String add : toAddress) { email.addBcc(add); } email.send(); }