List of usage examples for org.apache.commons.mail HtmlEmail setSubject
public Email setSubject(final String aSubject)
From source file:org.jcronjob.service.NoticeService.java
public void sendMessage(Long receiverId, Long workId, String emailAddress, String mobiles, String content) { try {//from w ww . j av a 2 s. c om HtmlEmail email = new HtmlEmail(); email.setCharset("UTF-8"); email.setHostName(config.getSmtpHost()); email.setSslSmtpPort(config.getSmtpPort().toString()); email.setAuthentication(config.getSenderEmail(), config.getPassword()); email.setFrom(config.getSenderEmail()); email.setSubject("cronjob"); email.setHtmlMsg(msgToHtml(receiverId, content)); email.addTo(emailAddress.split(",")); email.send(); Log log = new Log(); log.setType(0); log.setWorkerId(workId); log.setMessage(content); for (String receiver : emailAddress.split(",")) { log.setReceiver(receiver); log.setSendTime(new Date()); homeService.saveLog(log); } log.setType(1); for (String mobile : mobiles.split(",")) { //??POST String sendUrl = String.format(config.getSendUrl(), mobile, String.format(config.getTemplate(), content)); String url = sendUrl.substring(0, sendUrl.indexOf("?")); String postData = sendUrl.substring(sendUrl.indexOf("?") + 1); String message = HttpUtils.doPost(url, postData, "UTF-8"); log.setReceiver(mobile); log.setResult(message); log.setSendTime(new Date()); homeService.saveLog(log); logger.info(message); } } catch (Exception e) { e.printStackTrace(System.err); } }
From source file:org.jevis.jealarm.AlarmHandler.java
/** * Send the Alarm mail// w w w . ja v a 2 s. co m * * @param conf * @param alarm * @param body */ public void sendAlarm(Config conf, Alarm alarm, String body) { try { HtmlEmail email = new HtmlEmail(); // Email email = new SimpleEmail(); email.setHostName(conf.getSmtpServer()); email.setSmtpPort(conf.getSmtpPort()); email.setAuthenticator(new DefaultAuthenticator(conf.getSmtpUser(), conf.getSmtpPW())); email.setSSLOnConnect(conf.isSmtpSSL()); email.setFrom(conf.smtpFrom); email.setSubject(alarm.getSubject()); for (String recipient : alarm.getRecipient()) { email.addTo(recipient); } for (String bcc : alarm.getBcc()) { email.addBcc(bcc); } email.setHtmlMsg(body); email.send(); System.out.println("Alarm send: " + alarm.getSubject()); } catch (Exception ex) { System.out.println("cound not send Email"); ex.printStackTrace(); } }
From source file:org.jkandasa.email.blaster.EmailUtils.java
public static void sendEmail(AppProperties appProperties, Address address) throws EmailException, IOException { HtmlEmail email = initializeEmail(appProperties); StringBuilder attachmentBuilder = new StringBuilder(); String[] attachments = appProperties.getAttachments().split(","); for (String attachment : attachments) { File img = new File(attachment); if (appProperties.isEmbeddedAttachments()) { attachmentBuilder.append("<br><img src=cid:").append(email.embed(img)).append(">"); } else {/*from w w w .j av a 2s .c o m*/ email.attach(img); } } email.setSubject(getSubject(appProperties, address)); email.setHtmlMsg(getMessage(appProperties, address).replaceAll(ATTACHMENTS, attachmentBuilder.toString())); email.addTo(address.getEmails().split(EMAIL_SEPARATOR)); String sendReturn = email.send(); _logger.debug("Send Status:[{}]", sendReturn); _logger.debug("Email successfully sent to [{}]", address); }
From source file:org.meerkat.network.MailManager.java
/** * sendEmail//from w ww .j a v a 2s . co m * @param subject * @param message */ public final void sendEmail(String subject, String message) { this.refreshSettings(); HtmlEmail email = new HtmlEmail(); email.setHostName(getSMTPServer()); email.setSmtpPort(Integer.valueOf(getSMTPPort())); email.setSubject(subject); try { email.setHtmlMsg(message); } catch (EmailException e2) { log.error("Error in mail message. ", e2); } // SMTP security String security = getSMTPSecurity(); if (security.equalsIgnoreCase("STARTTLS")) { email.setTLS(true); } else if (security.equalsIgnoreCase("SSL/TLS")) { email.setSSL(true); email.setSslSmtpPort(String.valueOf(getSMTPPort())); } email.setAuthentication(getSMTPUser(), getSMTPPassword()); try { String[] toList = getTO().split(","); for (int i = 0; i < toList.length; i++) { email.addTo(toList[i].trim()); } } catch (EmailException e1) { log.error("EmailException: addTo(" + getTO() + "). " + e1.getMessage()); } try { email.setFrom(getFROM()); } catch (EmailException e1) { log.error("EmailException: setFrom(" + getFROM() + "). " + e1.getMessage()); } // Send the email try { email.send(); } catch (EmailException e) { log.error("Failed to send email!", e); } }
From source file:org.meerkat.network.MailManager.java
/** * testEmailSettingsFromWebService/* w w w . j a va2s. c om*/ * @param from * @param to * @param smtpServer * @param smtpPort * @param smtpSecurity * @param smtpUser * @param smtpPassword * @return */ public final String sendTestEmailSettingsFromWebService(String from, String to, String smtpServer, String smtpPort, String smtpSecurity, String smtpUser, String smtpPassword) { String resultString = "OK"; HtmlEmail email = new HtmlEmail(); email.setHostName(smtpServer); email.setSmtpPort(Integer.valueOf(smtpPort)); email.setSubject(testSubject); try { email.setHtmlMsg(testMessage); } catch (EmailException e2) { resultString = e2.getMessage(); return resultString; } // SMTP security if (smtpSecurity.equalsIgnoreCase("STARTTLS")) { email.setTLS(true); } else if (smtpSecurity.equalsIgnoreCase("SSLTLS")) { email.setSSL(true); email.setSslSmtpPort(String.valueOf(smtpPort)); } email.setAuthentication(smtpUser, smtpPassword); try { String[] toList = to.split(","); for (int i = 0; i < toList.length; i++) { email.addTo(toList[i].trim()); } } catch (EmailException e1) { resultString = "TO: " + e1.getMessage(); return resultString; } try { email.setFrom(from); } catch (EmailException e1) { resultString = "FROM: " + e1.getMessage(); return resultString; } // Send the email try { email.send(); } catch (EmailException e) { resultString = e.getMessage(); return resultString; } return resultString; }
From source file:org.ng200.openolympus.services.EmailService.java
@PreAuthorize(SecurityExpressionConstants.IS_ADMIN) public void sendEmail(String emailAddress, String subject, String view, String alternativeText, Map<String, Object> variables) throws MessagingException, EmailException { final Context ctx = new Context(); ctx.setVariables(variables);/*from w w w. j a v a2s .c om*/ final HtmlEmail email = new HtmlEmail(); email.setHostName(this.emailHost); email.setSmtpPort(this.emailHostPort); email.setAuthenticator(new DefaultAuthenticator(this.emailLogin, this.emailPassword)); email.setSSL(true); email.setFrom(this.emailLogin); email.setSubject(subject); final String htmlContent = this.templateEngine.process(view, ctx); email.setHtmlMsg(htmlContent); email.setTextMsg(alternativeText); email.addTo(emailAddress); email.send(); }
From source file:org.onehippo.forge.resetpassword.services.mail.MailServiceImpl.java
@Override public void sendMail(final MailMessage mailMessage) throws EmailException { final HtmlEmail email = new HtmlEmail(); final Session session = getSession(); if (session == null) { throw new EmailException("Unable to send mail; no mail session available"); }//from w w w .j a v a 2 s . co m email.setMailSession(session); email.addTo(mailMessage.getToMail(), mailMessage.getToName()); email.setFrom(mailMessage.getFromMail(), mailMessage.getFromName()); email.setSubject(mailMessage.getSubject()); // set the html message email.setHtmlMsg(mailMessage.getHtmlTextBody()); // set the alternative message email.setTextMsg(mailMessage.getPlainTextBody()); // send the email email.send(); }
From source file:org.opencron.server.service.NoticeService.java
public void sendMessage(List<User> users, Long workId, String emailAddress, String mobiles, String content) { Log log = new Log(); log.setIsread(false);/*from www . j av a2 s . com*/ log.setAgentId(workId); log.setMessage(content); //??? if (CommonUtils.isEmpty(emailAddress, mobiles)) { log.setType(Opencron.MsgType.WEBSITE.getValue()); log.setSendTime(new Date()); homeService.saveLog(log); return; } /** * ???? */ boolean emailSuccess = false; boolean mobileSuccess = false; Config config = configService.getSysConfig(); try { log.setType(Opencron.MsgType.EMAIL.getValue()); HtmlEmail email = new HtmlEmail(); email.setCharset("UTF-8"); email.setHostName(config.getSmtpHost()); email.setSslSmtpPort(config.getSmtpPort().toString()); email.setAuthentication(config.getSenderEmail(), config.getPassword()); email.setFrom(config.getSenderEmail()); email.setSubject("opencron"); email.setHtmlMsg(msgToHtml(content)); email.addTo(emailAddress.split(",")); email.send(); emailSuccess = true; /** * ?? */ log.setReceiver(emailAddress); log.setSendTime(new Date()); homeService.saveLog(log); } catch (Exception e) { e.printStackTrace(System.err); } /** * ???? */ try { for (String mobile : mobiles.split(",")) { //??POST String sendUrl = String.format(config.getSendUrl(), mobile, String.format(config.getTemplate(), content)); String url = sendUrl.substring(0, sendUrl.indexOf("?")); String postData = sendUrl.substring(sendUrl.indexOf("?") + 1); String message = HttpUtils.doPost(url, postData, "UTF-8"); log.setResult(message); logger.info(message); mobileSuccess = true; } log.setReceiver(mobiles); log.setType(Opencron.MsgType.SMS.getValue()); log.setSendTime(new Date()); homeService.saveLog(log); } catch (Exception e) { e.printStackTrace(System.err); } /** * ??,?? */ if (!mobileSuccess && !emailSuccess) { log.setType(Opencron.MsgType.WEBSITE.getValue()); log.setSendTime(new Date()); for (User user : users) { //?? log.setUserId(user.getUserId()); log.setReceiver(user.getUserName()); homeService.saveLog(log); } } }
From source file:org.oscarehr.oscar_apps.util.Log4JGmailExecutorTask.java
private void sendEmail() throws EmailException { HtmlEmail email = new HtmlEmail(); email.setHostName(smtpServer);//from ww w. ja v a2s .c om if (smtpUser != null && smtpPassword != null) email.setAuthentication(smtpUser, smtpPassword); if (smtpSslPort != null) { email.setSSL(true); email.setSslSmtpPort(smtpSslPort); } Session session = email.getMailSession(); Properties properties = session.getProperties(); properties.setProperty("mail.smtp.connectiontimeout", "20000"); properties.setProperty("mail.smtp.timeout", "20000"); email.addTo(recipientEmailAddress, recipientEmailAddress); email.setFrom(smtpUser, smtpUser); email.setSubject(subject); email.setHtmlMsg(contents); email.setTextMsg(contents); email.send(); }
From source file:org.oscarehr.util.EmailUtils.java
/** * This is a convenience method for sending and email to 1 recipient using the configuration file settings. * @throws EmailException // www . j av a 2s . co m */ public static void sendEmail(String toEmailAddress, String toName, String fromEmailAddress, String fromName, String subject, String textContents, String htmlContents) throws EmailException { HtmlEmail htmlEmail = getHtmlEmail(); htmlEmail.addTo(toEmailAddress, toName); htmlEmail.setFrom(fromEmailAddress, fromName); htmlEmail.setSubject(subject); if (textContents != null) htmlEmail.setTextMsg(textContents); if (htmlContents != null) htmlEmail.setHtmlMsg(htmlContents); htmlEmail.send(); }