List of usage examples for org.apache.commons.mail Email addBcc
public Email addBcc(final String... emails) throws EmailException
From source file:org.chenillekit.mail.services.impl.MailServiceImpl.java
private void setMailMessageHeaders(Email email, MailMessageHeaders headers) throws EmailException { email.setFrom(headers.getFrom());//from www . j ava2s.com try { email.setSubject(MimeUtility.encodeText(headers.getSubject(), headers.getCharset(), null)); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } for (String to : headers.getTo()) { email.addTo(to); } for (String cc : headers.getCc()) { email.addCc(cc); } for (String bcc : headers.getBcc()) { email.addBcc(bcc); } }
From source file:org.cobbzilla.mail.sender.SmtpMailSender.java
@Override public void send(SimpleEmailMessage message) throws EmailException { Email email = constructEmail(message); email.setHostName(config.getHost()); email.setSmtpPort(config.getPort()); if (config.getHasMailUser()) { email.setAuthenticator(new DefaultAuthenticator(config.getUser(), config.getPassword())); }//w ww. ja v a2 s . c om email.setTLS(config.isTlsEnabled()); email.setSubject(message.getSubject()); if (message.getToName() != null) { email.addTo(message.getToEmail(), message.getToName()); } else { email.addTo(message.getToEmail()); } if (message.getBcc() != null) { email.addBcc(message.getBcc()); } if (message.getCc() != null) { email.addCc(message.getCc()); } if (message.getFromName() != null) { email.setFrom(message.getFromEmail(), message.getFromName()); } else { email.setFrom(message.getFromEmail()); } sendEmail_internal(email); }
From source file:org.fao.geonet.util.MailUtil.java
/** * Send a plain text mail. Will look on the settings directly to know the * remitent// w ww . j a v a 2 s.c o m * * @param toAddress * @param subject * @param message * @param settings * @throws EmailException */ public static Boolean sendMail(List<String> toAddress, String subject, String message, SettingManager settings) { // Create data information to compose the mail Email email = new SimpleEmail(); configureBasics(settings, email); email.setSubject(subject); try { email.setMsg(message); } 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
/** * Send a plain text mail. Will look on the settings directly to know the * remitent//from w w w . j a v a2s . c om * * @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
/** * Send a plain text mail/* w ww . j a va2 s .co m*/ * * @param toAddress * @param from * @param subject * @param message * @throws EmailException */ public static Boolean sendMail(List<String> toAddress, String from, String subject, String message, SettingManager settings) { Email email = new SimpleEmail(); String username = settings.getValue(Settings.SYSTEM_FEEDBACK_MAILSERVER_USERNAME); String password = settings.getValue(Settings.SYSTEM_FEEDBACK_MAILSERVER_PASSWORD); Boolean ssl = settings.getValueAsBool(Settings.SYSTEM_FEEDBACK_MAILSERVER_SSL, false); Boolean tls = settings.getValueAsBool(Settings.SYSTEM_FEEDBACK_MAILSERVER_TLS, false); String hostName = settings.getValue(Settings.SYSTEM_FEEDBACK_MAILSERVER_HOST); Integer smtpPort = Integer.valueOf(settings.getValue(Settings.SYSTEM_FEEDBACK_MAILSERVER_PORT)); Boolean ignoreSslCertificateErrors = settings .getValueAsBool(Settings.SYSTEM_FEEDBACK_MAILSERVER_IGNORE_SSL_CERTIFICATE_ERRORS, false); configureBasics(hostName, smtpPort, from, username, password, email, ssl, tls, ignoreSslCertificateErrors); email.setSubject(subject); try { email.setMsg(message); } 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 false; } } 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 www.j ava 2 s . com*/ 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(); }
From source file:org.flowable.engine.impl.bpmn.behavior.MailActivityBehavior.java
protected void addBcc(Email email, String bcc) { String[] bccs = splitAndTrim(bcc); if (bccs != null) { for (String b : bccs) { try { email.addBcc(b); } catch (EmailException e) { throw new FlowableException("Could not add " + b + " as bcc recipient", e); }/*from w ww . ja v a 2 s . c om*/ } } }
From source file:org.jwebsocket.plugins.mail.MailPlugInService.java
/** * * @param aToken/*from w w w . j a v a2 s .c o m*/ * @return */ public Token sendMail(Token aToken) { String lFrom = aToken.getString("from", "[unknown]"); String lTo = aToken.getString("to"); String lCC = aToken.getString("cc"); String lBCC = aToken.getString("bcc"); String lSubject = aToken.getString("subject"); String lBody = aToken.getString("body"); Boolean lIsHTML = aToken.getBoolean("html", false); List<Object> lAttachedFiles = aToken.getList("attachments"); String lMsg; // instantiate response token Token lResponse = TokenFactory.createToken(); Map<String, String> lMap = new FastMap<String, String>(); if (lFrom != null && lFrom.length() > 0) { lMap.put("from", lFrom); } if (lTo != null && lTo.length() > 0) { lMap.put("to", lTo); } if (lCC != null && lCC.length() > 0) { lMap.put("cc", lCC); } if (lBCC != null && lBCC.length() > 0) { lMap.put("bcc", lBCC); } if (lSubject != null && lSubject.length() > 0) { lMap.put("subject", lSubject); } if (lBody != null && lBody.length() > 0) { lMap.put("body", lBody); } // Create the attachment List<EmailAttachment> lEmailAttachments = new FastList<EmailAttachment>(); if (lAttachedFiles != null) { for (Object lAttachedFile : lAttachedFiles) { EmailAttachment lAttachment = new EmailAttachment(); lAttachment.setPath((String) lAttachedFile); lAttachment.setDisposition(EmailAttachment.ATTACHMENT); // lAttachment.setDescription( "Picture of John" ); // lAttachment.setName( "John" ); lEmailAttachments.add(lAttachment); } } // Create the lEmail message if (mLog.isDebugEnabled()) { mLog.debug("Sending e-mail to " + lTo + " with subject '" + lSubject + "'..."); } try { Email lEmail; if (lIsHTML) { lEmail = new HtmlEmail(); } else { lEmail = new MultiPartEmail(); } lEmail.setHostName(mSettings.getSmtpHost()); lEmail.setSmtpPort(mSettings.getSmtpPort()); if (mSettings.getSmtpAuth()) { lEmail.setAuthentication(mSettings.getSmtpUser(), mSettings.getSmtpPassword()); } if (mSettings.getSmtpPop3Before()) { lEmail.setPopBeforeSmtp(true, mSettings.getPop3Host(), mSettings.getPop3User(), mSettings.getPop3Password()); } if (lFrom != null && lFrom.length() > 0) { lEmail.setFrom(lFrom); } if (lTo != null && lTo.length() > 0) { String[] lToSplit = lTo.split(";"); for (String lToSplit1 : lToSplit) { if (lToSplit1 != null && lToSplit1.length() > 0) { lEmail.addTo(lToSplit1.trim()); } } } if (lCC != null && lCC.length() > 0) { String[] lCCSplit = lCC.split(";"); for (String lCCSplit1 : lCCSplit) { if (lCCSplit1 != null && lCCSplit1.length() > 0) { lEmail.addCc(lCCSplit1.trim()); } } } if (lBCC != null && lBCC.length() > 0) { String[] lBCCSplit = lBCC.split(";"); for (String lBCCSplit1 : lBCCSplit) { if (lBCCSplit1 != null && lBCCSplit1.length() > 0) { lEmail.addBcc(lBCCSplit1.trim()); } } } if (lSubject != null && lSubject.length() > 0) { lEmail.setSubject(lSubject); } if (lBody != null && lBody.length() > 0) { if (lIsHTML) { HtmlEmail lHTML = ((HtmlEmail) lEmail); /* * URL lURL = new * URL("http://five-feet-further.com/aschulze/images/portrait_web_kleiner.jpg"); * String lCID = ((HtmlEmail )lEmail).embed(lURL, "five feet * further logo"); * * //url = new URL( * "http://five-feet-further.com/resources/css/IJX4FWDocu.css" * ); // String css = ((HtmlEmail)lEmail).embed( url, "name * of css" ); * * ((HtmlEmail )lEmail).setHtmlMsg( "<html><body>" + "<style * type=\"text/css\">" + "h1 { " + " font-family:arial, * helvetica, sans-serif;" + " font-weight:bold;" + " * font-size:18pt;" + "}" + "</style>" + // "<link * href=\"cid:" + css + "\" type=\"text/css\" * rel=\"stylesheet\">" + "<p><img src=\"cid:" + lCID + * "\"></p>" + "<p><img * src=\"http://five-feet-further.com/aschulze/images/portrait_web_kleiner.jpg\"></p>" * + lItem + "</body></html>"); */ /* * // Now the message body. Multipart mp = new * MimeMultipart(); * * BodyPart textPart = new MimeBodyPart(); // sets type to * "text/plain" textPart.setText("Kann Ihr Browser keine * HTML-Mails darstellen?"); * * BodyPart pixPart = new MimeBodyPart(); * pixPart.setContent(lMsg, "text/html"); * * // Collect the Parts into the MultiPart * mp.addBodyPart(textPart); mp.addBodyPart(pixPart); * * // Put the MultiPart into the Message ((HtmlEmail) * lEmail).setContent((MimeMultipart)mp); ((HtmlEmail) * lEmail).buildMimeMessage(); * * /* * // ((HtmlEmail) lEmail).setContent(lMsg, * Email.TEXT_HTML); * * // lHeaders.put("Innotrade-Id", "4711-0815"); // * lHTML.setHeaders(lHeaders); // ((HtmlEmail) * lEmail).setCharset("UTF-8"); // ((HtmlEmail) * lEmail).setMsg(lMsg); lMM.setHeader("Innotrade-Id", * "4711-0815"); * * // ((HtmlEmail) lEmail).setContent(lTxtMsg, * Email.TEXT_PLAIN); */ // String lTxtMsg = "Your Email-Client does not support HTML messages."; lHTML.setHtmlMsg(lBody); // lHTML.setTextMsg(lTxtMsg); } else { lEmail.setMsg(lBody); } } // add attachment(s), if such for (EmailAttachment lAttachment : lEmailAttachments) { ((MultiPartEmail) lEmail).attach(lAttachment); } // send the Email String lMsgId = lEmail.send(); if (mLog.isInfoEnabled()) { lMsg = "Email successfully sent" + " from " + (lFrom != null ? lFrom : "(no sender)") + " to " + (lTo != null ? lTo : "(no recipient)") + " cc " + (lCC != null ? lCC : "(no recipient)") + ", subject " + (lSubject != null ? "'" + lSubject + "'" : "(no subject)") + ", msgId " + lMsgId; mLog.info(lMsg); } lResponse.setInteger("code", 0); lResponse.setString("msg", "ok"); lResponse.setString("msgId", lMsgId); } catch (EmailException lEx) { lMsg = lEx.getClass().getSimpleName() + " (" + lEx.getCause().getClass().getSimpleName() + "): " + lEx.getMessage(); mLog.error(lMsg); lResponse.setInteger("code", -1); lResponse.setString("msg", lMsg); } return lResponse; }
From source file:org.ms123.common.workflow.tasks.TaskMailExecutor.java
protected void addBcc(Email email, String bcc) { String[] bccs = splitAndTrim(bcc); if (bccs != null) { for (String b : bccs) { try { email.addBcc(b); } catch (EmailException e) { throw new RuntimeException("TaskMailExecutor:Could not add " + b + " as bcc recipient", e); }/* w w w . j av a2 s. c o m*/ } } }
From source file:org.ms123.common.workflow.TaskSendExecutor.java
protected void addBcc(Email email, String bcc) { String[] bccs = splitAndTrim(bcc); if (bccs != null) { for (String b : bccs) { try { email.addBcc(b); } catch (EmailException e) { throw new RuntimeException("TaskSendExecutor:Could not add " + b + " as bcc recipient", e); }/*from www .j a va 2 s . co m*/ } } }