List of usage examples for org.apache.commons.mail HtmlEmail setSubject
public Email setSubject(final String aSubject)
From source file:com.perceptive.epm.perkolcentral.bl.EmployeeBL.java
private void sendMailToPerceptiveOpsTeam(EmployeeBO employeeBO) throws Exception { try {//from w ww . j av a 2 s .c o m //Send the mail HtmlEmail emailToSend = new HtmlEmail(); emailToSend.setHostName(email.getHostName()); String messageTemplateAdded = "<html>\n" + "<head>\n" + "</head>\n" + "\n" + "<body style=\"font:Georgia; font-size:12px;\">\n" + "<p>Dear All,</p>\n" + "<blockquote>\n" + " <p>A new employee has joined Perceptive Kolkata.</p>\n" + "</blockquote>\n" + "<ul>\n" + " <li><strong><em>User Name</em></strong>: <strong>%s</strong></li>\n" + " <li><em><strong>User Short Id</strong></em>: <strong>%s</strong></li>\n" + " <li><em><strong>Employee Id</strong></em>: <strong>%s</strong></li>\n" + " <li><strong><em>User Email-Id</em></strong>:<strong> %s</strong></li>\n" + " <li><em><strong>Mobile Number</strong></em>:<strong> %s</strong></li>\n" + " <li><em><strong>Job Title</strong></em> : <strong>%s</strong></li>\n" + "</ul>\n" + "<p>Please take following actions.</p>\n" + "<ul>\n" + " <li>Access to Rally.</li>\n" + " <li>Access to Salesforce.</li>\n" + " <li>Access to Confluence.</li>\n" + " <li>Access to Perceptive AD.</li>\n" + " <li>Access to TFS.</li>\n" + "</ul>\n" + "<p>Thanks,</p>\n" + "<blockquote>\n" + " <p>Perceptive Kolkata Central( http://10.195.17.14/PerceptiveKolkataCentral )</p>\n" + "</blockquote>\n" + "</body>\n" + "</html>"; String messageToSend = String.format(messageTemplateAdded, employeeBO.getEmployeeName(), employeeBO.getEmployeeUid(), employeeBO.getEmployeeId().toString(), employeeBO.getEmail(), employeeBO.getMobileNumber(), employeeBO.getJobTitle()); emailToSend.setHtmlMsg(messageToSend); //emailToSend.setTextMsg(StringEscapeUtils.escapeHtml(messageToSend)); emailToSend.getToAddresses().clear(); emailToSend.addTo("per.special.rad.operations@perceptivesoftware.com", "RAD - Operations"); emailToSend.addTo("radops@perceptivesoftware.com", "RAD - Operations Team"); Collection<EmployeeBO> allEmployeesNeedToGetMail = getAllEmployeesKeyedByGroupId() .get(Integer.valueOf("14")); for (EmployeeBO item : allEmployeesNeedToGetMail) { emailToSend.addCc(item.getEmail(), item.getEmployeeName()); } //emailToSend.setFrom("PerceptiveKolkataCentral@perceptivesoftware.com", "Perceptive Kolkata Central"); emailToSend.setFrom("EnterpriseSoftwareKolkata@lexmark.com", "Enterprise Software Kolkata"); emailToSend.setSubject( String.format("New employee joined @ Lexmark Kolkata : %s", employeeBO.getEmployeeName())); emailToSend.send(); } catch (Exception ex) { throw new ExceptionWrapper(ex); } }
From source file:gov.osti.services.Metadata.java
/** * Send an email notification on APPROVAL of DOE CODE records. * * @param md the METADATA to send notification for *//*ww w.j a v a 2 s .c o m*/ private static void sendApprovalNotification(DOECodeMetadata md) { HtmlEmail email = new HtmlEmail(); email.setCharset(org.apache.commons.mail.EmailConstants.UTF_8); email.setHostName(EMAIL_HOST); // if HOST or record OWNER or PROJECT MANAGER NAME isn't set, cannot send if (StringUtils.isEmpty(EMAIL_HOST) || null == md || StringUtils.isEmpty(md.getOwner()) || StringUtils.isEmpty(PM_NAME)) return; // only has meaning for APPROVED records if (!Status.Approved.equals(md.getWorkflowStatus())) return; try { // get the OWNER information User owner = UserServices.findUserByEmail(md.getOwner()); if (null == owner) { log.warn("Unable to locate USER information for Code ID: " + md.getCodeId()); return; } Long codeId = md.getCodeId(); // lookup previous Snapshot status info for item EntityManager em = DoeServletContextListener.createEntityManager(); TypedQuery<MetadataSnapshot> querySnapshot = em .createNamedQuery("MetadataSnapshot.findByCodeIdLastNotStatus", MetadataSnapshot.class) .setParameter("status", DOECodeMetadata.Status.Approved).setParameter("codeId", codeId); String lastApprovalFor = "submitted/announced"; List<MetadataSnapshot> results = querySnapshot.setMaxResults(1).getResultList(); for (MetadataSnapshot ms : results) { lastApprovalFor = ms.getSnapshotKey().getSnapshotStatus().toString().toLowerCase(); } String softwareTitle = md.getSoftwareTitle().replaceAll("^\\h+|\\h+$", ""); email.setFrom(EMAIL_FROM); email.setSubject("Approved -- DOE CODE ID: " + codeId + ", " + softwareTitle); email.addTo(md.getOwner()); // if email is provided, BCC the Project Manager if (!StringUtils.isEmpty(PM_EMAIL)) email.addBcc(PM_EMAIL, PM_NAME); StringBuilder msg = new StringBuilder(); msg.append("<html>"); msg.append("Dear ").append(owner.getFirstName()).append(" ").append(owner.getLastName()).append(":"); msg.append("<P>Thank you -- your ").append(lastApprovalFor).append(" project, DOE CODE ID: <a href=\"") .append(SITE_URL).append("/biblio/").append(codeId).append("\">").append(codeId) .append("</a>, has been approved. It is now <a href=\"").append(SITE_URL) .append("\">searchable</a> in DOE CODE by, for example, title or CODE ID #.</P>"); // OMIT the following for BUSINESS TYPE software, or last ANNOUNCED software if (!DOECodeMetadata.Type.B.equals(md.getSoftwareType()) && !lastApprovalFor.equalsIgnoreCase("announced")) { msg.append( "<P>You may need to continue editing your project to announce it to the Department of Energy ") .append("to ensure announcement and dissemination in accordance with DOE statutory responsibilities. For more information please see ") .append("<a href=\"").append(SITE_URL) .append("/faq#what-does-it-mean-to-announce\">What does it mean to announce scientific code to DOE CODE?</a></P>"); } msg.append( "<P>If you have questions such as What are the benefits of getting a DOI for code or software?, see the ") .append("<a href=\"").append(SITE_URL).append("/faq\">DOE CODE FAQs</a>.</P>"); msg.append( "<P>If we can be of assistance, please do not hesitate to <a href=\"mailto:doecode@osti.gov\">Contact Us</a>.</P>"); msg.append("<P>Sincerely,</P>"); msg.append("<P>").append(PM_NAME).append("<BR/>Product Manager for DOE CODE<BR/>USDOE/OSTI</P>"); msg.append("</html>"); email.setHtmlMsg(msg.toString()); email.send(); } catch (EmailException e) { log.error("Unable to send APPROVAL notification for #" + md.getCodeId()); log.error("Message: " + e.getMessage()); } }
From source file:net.wildpark.dswp.supports.MailService.java
public boolean sendEmail(String to, String textBody) { try {//from w w w . j av a 2 s . com HtmlEmail email = new HtmlEmail(); email.setCharset("utf-8"); email.setHostName("mail.wildpark.net"); email.setSmtpPort(25); email.setAuthenticator(new DefaultAuthenticator("informer@mksat.net", "22v5C728")); email.setFrom("informer@mksat.net"); email.setSubject("Automatic message from darkside.wildpark.net"); email.setHtmlMsg(textBody); email.addTo(to); email.send(); logFacade.create(new Log("Sended mail " + to)); } catch (EmailException ex) { logFacade.create(new Log("Error with mail sending", ex, LoggerLevel.ERROR)); System.out.println(ex); return false; } return true; }
From source file:nl.b3p.kaartenbalie.struts.Mailer.java
public ActionMessages send(ActionMessages errors) throws AddressException, MessagingException, IOException, Exception { HtmlEmail email = new HtmlEmail(); String[] ds = null;// ww w.j a v a 2 s . c om if (mailTo != null && mailTo.trim().length() != 0) { ds = mailTo.split(","); for (int i = 0; i < ds.length; i++) { email.addTo(ds[i]); } } if (mailCc != null && mailCc.trim().length() != 0) { ds = mailCc.split(","); for (int i = 0; i < ds.length; i++) { email.addCc(ds[i]); } } if (mailBcc != null && mailBcc.trim().length() != 0) { ds = mailBcc.split(","); for (int i = 0; i < ds.length; i++) { email.addBcc(ds[i]); } } email.setFrom(mailFrom); email.setSubject(subject); email.setHostName(mailHost); if (isReturnReceipt()) { email.addHeader("Disposition-Notification-To", mailFrom); } if (attachmentName == null) { attachmentName = "attachment"; } if (attachment != null) { URL attachUrl = null; try { attachUrl = new URL(attachment); email.attach(attachUrl, attachmentName, attachmentName); } catch (MalformedURLException mfue) { } } if (attachmentDataSource != null) { email.attach(attachmentDataSource, attachmentName, attachmentName); } email.setMsg(createHTML()); // send the email email.send(); return errors; }
From source file:org.apache.unomi.plugins.mail.actions.SendMailAction.java
public int execute(Action action, Event event) { String from = (String) action.getParameterValues().get("from"); String to = (String) action.getParameterValues().get("to"); String cc = (String) action.getParameterValues().get("cc"); String bcc = (String) action.getParameterValues().get("bcc"); String subject = (String) action.getParameterValues().get("subject"); String template = (String) action.getParameterValues().get("template"); ST stringTemplate = new ST(template); stringTemplate.add("profile", event.getProfile()); stringTemplate.add("event", event); // load your HTML email template String htmlEmailTemplate = stringTemplate.render(); // define you base URL to resolve relative resource locations try {// www.j a v a2 s. c o m new URL("http://www.apache.org"); } catch (MalformedURLException e) { // } // create the email message HtmlEmail email = new ImageHtmlEmail(); // email.setDataSourceResolver(new DataSourceResolverImpl(url)); email.setHostName(mailServerHostName); email.setSmtpPort(mailServerPort); email.setAuthenticator(new DefaultAuthenticator(mailServerUsername, mailServerPassword)); email.setSSLOnConnect(mailServerSSLOnConnect); try { email.addTo(to); email.setFrom(from); if (cc != null && cc.length() > 0) { email.addCc(cc); } if (bcc != null && bcc.length() > 0) { email.addBcc(bcc); } email.setSubject(subject); // set the html message email.setHtmlMsg(htmlEmailTemplate); // set the alternative message email.setTextMsg("Your email client does not support HTML messages"); // send the email email.send(); } catch (EmailException e) { logger.error("Cannot send mail", e); } return EventService.NO_CHANGE; }
From source file:org.cerberus.service.email.impl.sendMail.java
public static void sendHtmlMail(String host, int port, String body, String subject, String from, String to, String cc) throws Exception { HtmlEmail email = new HtmlEmail(); email.setSmtpPort(port);//from w w w . j a v a2s .c om email.setDebug(false); email.setHostName(host); email.setFrom(from); email.setSubject(subject); email.setHtmlMsg(body); String[] destinataire = to.split(";"); for (int i = 0; i < destinataire.length; i++) { String name; String emailaddress; if (destinataire[i].contains("<")) { String[] destinatairedata = destinataire[i].split("<"); name = destinatairedata[0].trim(); emailaddress = destinatairedata[1].replace(">", "").trim(); } else { name = ""; emailaddress = destinataire[i]; } email.addTo(emailaddress, name); } String[] copy = cc.split(";"); for (int i = 0; i < copy.length; i++) { String namecc; String emailaddresscc; if (copy[i].contains("<")) { String[] copydata = copy[i].split("<"); namecc = copydata[0].trim(); emailaddresscc = copydata[1].replace(">", "").trim(); } else { namecc = ""; emailaddresscc = copy[i]; } email.addCc(emailaddresscc, namecc); } email.setTLS(true); email.send(); }
From source file:org.fao.geonet.util.MailUtil.java
/** * Send an html mail. Will look on the settings directly to know the * remitent//w w w. java2s . c o m * * @param toAddress * @param subject * @param htmlMessage * @param settings * @throws EmailException */ public static Boolean sendHtmlMail(List<String> toAddress, String subject, String htmlMessage, SettingManager settings) { // Create data information to compose the mail HtmlEmail email = new HtmlEmail(); configureBasics(settings, email); email.setSubject(subject); try { email.setHtmlMsg(htmlMessage); } catch (EmailException e1) { Log.error("Error setting email HTML content. Subject:" + subject, 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
/** * Send an html mail with atachments/* w ww . j av a2s . c om*/ * * @param toAddress * @param from * @param subject * @param htmlMessage * @param attachment * @throws EmailException */ public static Boolean sendHtmlMailWithAttachment(List<String> toAddress, String from, String subject, String htmlMessage, List<EmailAttachment> attachment, SettingManager settings) { // Create data information to compose the mail HtmlEmail email = new HtmlEmail(); 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); for (EmailAttachment attach : attachment) { try { email.attach(attach); } catch (EmailException e) { Log.error(LOG_MODULE_NAME, "Error attaching attachment " + attach.getName(), e); } } email.setSubject(subject); try { email.setHtmlMsg(htmlMessage); } catch (EmailException e1) { Log.error(LOG_MODULE_NAME, "Error setting email HTML 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.gravidence.gravifon.email.ApacheCommonsEmailSender.java
@Override public boolean send(String toAddress, String toName, String subject, String htmlMessage, String textMessage) { HtmlEmail email = new HtmlEmail(); email.setHostName(host);//w w w.j a v a 2 s .c o m email.setSslSmtpPort(port); email.setAuthenticator(new DefaultAuthenticator(username, password)); email.setSSLOnConnect(true); try { if (StringUtils.isBlank(toName)) { email.addTo(toAddress); } else { email.addTo(toAddress, toName); } email.setFrom(fromAddress, fromName); email.setSubject(subject); if (htmlMessage != null) { email.setHtmlMsg(htmlMessage); } if (textMessage != null) { email.setTextMsg(textMessage); } email.send(); } catch (EmailException ex) { // TODO think about throwing GravifonException LOGGER.warn(String.format("Failed to send an email to %s", toAddress), ex); return false; } return true; }
From source file:org.infoglue.cms.util.mail.MailService.java
/** * * @param from the sender of the email.//from ww w . j a v a2 s . com * @param to the recipient of the email. * @param subject the subject of the email. * @param content the body of the email. * @throws SystemException if the email couldn't be sent due to some mail server exception. */ public void sendHTML(String from, String to, String cc, String bcc, String bounceAddress, String replyTo, String subject, String content, String encoding) throws SystemException { try { HtmlEmail email = new HtmlEmail(); String mailServer = CmsPropertyHandler.getMailSmtpHost(); String mailPort = CmsPropertyHandler.getMailSmtpPort(); String systemEmailSender = CmsPropertyHandler.getSystemEmailSender(); email.setHostName(mailServer); if (mailPort != null && !mailPort.equals("")) email.setSmtpPort(Integer.parseInt(mailPort)); boolean needsAuthentication = false; try { needsAuthentication = new Boolean(CmsPropertyHandler.getMailSmtpAuth()).booleanValue(); } catch (Exception ex) { needsAuthentication = false; } if (needsAuthentication) { final String userName = CmsPropertyHandler.getMailSmtpUser(); final String password = CmsPropertyHandler.getMailSmtpPassword(); email.setAuthentication(userName, password); } email.setBounceAddress(systemEmailSender); email.setCharset(encoding); if (logger.isInfoEnabled()) { logger.info("systemEmailSender:" + systemEmailSender); logger.info("to:" + to); logger.info("from:" + from); logger.info("mailServer:" + mailServer); logger.info("mailPort:" + mailPort); logger.info("cc:" + cc); logger.info("bcc:" + bcc); logger.info("replyTo:" + replyTo); logger.info("subject:" + subject); } if (to.indexOf(";") > -1) { cc = to; to = from; } String limitString = CmsPropertyHandler.getEmailRecipientLimit(); if (limitString != null && !limitString.equals("-1")) { try { Integer limit = new Integer(limitString); int count = 0; if (cc != null) count = count + cc.split(";").length; if (bcc != null) count = count + bcc.split(";").length; logger.info("limit: " + limit + ", count: " + count); if (count > limit) throw new Exception("You are not allowed to send mail to more than " + limit + " recipients at a time. This is specified in app settings."); } catch (NumberFormatException e) { logger.error("Exception validating number of recipients in mailservice:" + e.getMessage(), e); } } email.addTo(to, to); email.setFrom(from, from); if (cc != null) email.setCc(createInternetAddressesList(cc)); if (bcc != null) email.setBcc(createInternetAddressesList(bcc)); if (replyTo != null) email.setReplyTo(createInternetAddressesList(replyTo)); email.setSubject(subject); email.setHtmlMsg(content); email.setTextMsg("Your email client does not support HTML messages"); email.send(); logger.info("Email sent!"); } catch (Exception e) { logger.error("An error occurred when we tried to send this mail:" + e.getMessage(), e); throw new SystemException("An error occurred when we tried to send this mail:" + e.getMessage(), e); } }