List of usage examples for org.apache.commons.mail SimpleEmail setContent
public void setContent(final Object aObject, final String aContentType)
From source file:com.ms.commons.message.impl.sender.AbstractEmailSender.java
private SimpleEmail makeSimpleEmail(MsunMail mail, String charset) throws EmailException { SimpleEmail email = new SimpleEmail(); email.setCharset(charset);/*from w w w.ja va 2s.c o m*/ email.setContent(mail.getMessage(), "text/plain" + ";charset=" + charset); return email; }
From source file:com.pearson.openideas.cq5.components.form.SendContributorEmail.java
/** * This method sends the contact us email. *//*from w w w. j a va2 s. c o m*/ public void send() { // get the MailService from the CQ server and set up the mail object messageGatewayService = getSlingScriptHelper().getService(MessageGatewayService.class); mailMessageGateway = messageGatewayService.getGateway(SimpleEmail.class); SimpleEmail email = new SimpleEmail(); // build the properties of the email try { email.addTo(toEmail); email.setFrom(toEmail); } catch (EmailException e) { log.error("Trouble adding email address " + toEmail, e); } email.setSubject(emailSubject); StringBuilder template = new StringBuilder(); template.append("<div style='background:#fcf5ea'>"); template.append( "<img src='" + headerLogoUrl + "' style='width:165px;height:80px;margin: 8px 8px 20px 8px;' />") .append(NEW_LINE_CHAR); template.append( "<div style='background-image: linear-gradient(top, rgb(68,68,68) 36%, rgb(51,51,51) 68%, rgb(51,51,51) 84%);background-image: -o-linear-gradient(top, rgb(68,68,68) 36%, rgb(51,51,51) 68%, rgb(51,51,51) 84%);background-image: -moz-linear-gradient(top, rgb(68,68,68) 36%, rgb(51,51,51) 68%, rgb(51,51,51) 84%);background-image: -webkit-linear-gradient(top, rgb(68,68,68) 36%, rgb(51,51,51) 68%, rgb(51,51,51) 84%);background-image: -ms-linear-gradient(top, rgb(68,68,68) 36%, rgb(51,51,51) 68%, rgb(51,51,51) 84%);background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0.36, rgb(68,68,68)),color-stop(0.68, rgb(51,51,51)),color-stop(0.84, rgb(51,51,51)));padding: 4px 0 10px 8px;height:16px;width:100%; margin: 0 0 20px 0;'></div>"); template.append("<div style='margin:0 0 0 10px'>"); template.append("Name: ").append(name).append(NEW_LINE_CHAR); template.append("Email: ").append(userEmail).append(NEW_LINE_CHAR); template.append("Subject: ").append(subject).append(NEW_LINE_CHAR); template.append("Comments: ").append(comments).append(NEW_LINE_CHAR); template.append("</div>"); template.append("<a href='http://uk.pearson.com/legal-notice.html'>Terms and Conditions</a><br/>"); template.append( "<div style='background:#393a3a; width:100%; padding:10px 10px 10px 10px; height:45px;margin: 20px 0 0;'><img src='" + footerLogoLeftUrl + "' style='float:left;width:140px; height:15px; margin-top: 15px'><img src='" + footerLogoRightUrl + "' style='float:right; width:105px;height:25px;margin:7px 17px 0 0;'></div>"); template.append("</div>"); email.setContent(template.toString(), "text/html"); if (mailMessageGateway != null) { mailMessageGateway.send(email); } else { log.error("email message gateway was null, no email sent."); } sendUserEmail(userEmail); }
From source file:com.pearson.openideas.cq5.components.form.SendContributorEmail.java
/** * This method sends an email saying thank you for contacting us. *//*from w ww . j av a 2s . c o m*/ public void sendUserEmail(String userEmailAddress) { SimpleEmail userEmail = new SimpleEmail(); // build the properties of the email try { userEmail.addTo(userEmailAddress); userEmail.setFrom(toEmail); } catch (EmailException e) { log.error("Trouble adding email address", e); } userEmail.setSubject("Open Ideas - Thank you for getting in touch"); // get parameters from StringBuilder template = new StringBuilder(); template.append("<table style='background:#fcf5ea; width:100%;'><tr><td>"); template.append("<img src='" + headerLogoUrl + "' style='width:165px;height:80px;margin: 8px 8px 20px 8px;' /></td></tr>"); template.append( "<tr><td height='30' style='bgcolor:#393a3a;background:#393a3a;background-image:linear-gradient(top, rgb(68,68,68) 36%, rgb(51,51,51) 68%, rgb(51,51,51) 84%);background-image: -o-linear-gradient(top, rgb(68,68,68) 36%, rgb(51,51,51) 68%, rgb(51,51,51) 84%);background-image: -moz-linear-gradient(top, rgb(68,68,68) 36%, rgb(51,51,51) 68%, rgb(51,51,51) 84%);background-image: -webkit-linear-gradient(top, rgb(68,68,68) 36%, rgb(51,51,51) 68%, rgb(51,51,51) 84%);background-image: -ms-linear-gradient(top, rgb(68,68,68) 36%, rgb(51,51,51) 68%, rgb(51,51,51) 84%);background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0.36, rgb(68,68,68)),color-stop(0.68, rgb(51,51,51)),color-stop(0.84, rgb(51,51,51))); width:100%;'></td></tr>"); template.append("<tr><td><br>Hello ").append(name).append(",<br><br></td></tr>"); template.append("<tr><td>Thank you for getting in touch.").append("<br><br></td></tr>"); template.append("<tr><td>We will do our best to get back to you as soon as possible.").append("</td></tr>"); template.append("<tr><td><br>Best wishes,").append("</td></tr>"); template.append("<tr><td>The Open Ideas Team</td></tr>"); template.append( "<tr><td><a style='margin:10px 0 0 0;' href='http://research.pearson.com'>http://research.pearson.com</a><br><br></td></tr></table>"); template.append("<table style='background:#fcf5ea; width:100%; border-collapse:collapse'>"); template.append( "<tr style='background:#393a3a; width:100%; padding:10px 10px 10px 10px; height:45px;margin: 20px 0 0;'><td style='width:50%;background:#393a3a;'><img src='" + footerLogoLeftUrl + "' style='float:left;width:140px; height:15px; margin:15px 0 15px 10px;'></td><td style='background:#393a3a; width:50%; text-align:right;'><img src='" + footerLogoRightUrl + "' style='float:right; width:105px;height:25px;margin:10px 10px;'></td></tr>"); template.append("</table>"); userEmail.setContent(template.toString(), "text/html"); if (mailMessageGateway != null) { mailMessageGateway.send(userEmail); } else { log.error("email message gateway was null, no user email sent."); } }
From source file:org.exoplatform.social.notification.mail.FakeMailService.java
@Override public void sendMessage(Message message) throws Exception { SimpleEmail email = new SimpleEmail(); email.setHostName("localhost"); email.setSmtpPort(2525);// w w w. ja v a 2s . co m email.setStartTLSEnabled(true); email.setFrom(message.getFrom()); email.setSubject(message.getSubject()); email.setContent(message.getBody(), EmailConstants.TEXT_HTML); email.addTo(message.getTo()); email.send(); }
From source file:org.sigmah.server.mail.MailSenderImpl.java
/** * {@inheritDoc}/* w ww . ja va2 s. c om*/ */ @Override public void send(final Email email) throws EmailException { if (email == null || ArrayUtils.isEmpty(email.getToAddresses())) { // does nothing. throw new EmailException("Email object null or invalid."); } // Simple email. final SimpleEmail simpleEmail = new SimpleEmail(); // Mail content parameters. simpleEmail.setFrom(email.getFromAddress(), email.getFromName()); for (final String address : email.getToAddresses()) { simpleEmail.addTo(address); } if (ArrayUtils.isNotEmpty(email.getCcAddresses())) { for (final String address : email.getCcAddresses()) { simpleEmail.addCc(address); } } simpleEmail.setSubject(email.getSubject()); simpleEmail.setContent(email.getContent(), email.getContentType()); // Mail sending parameters. simpleEmail.setCharset(email.getEncoding()); simpleEmail.setHostName(email.getHostName()); simpleEmail.setSmtpPort(email.getSmtpPort()); // Authentication is needed. final String userName = email.getAuthenticationUserName(); final String password = email.getAuthenticationPassword(); if (userName != null && password != null) { simpleEmail.setAuthentication(userName, password); } // Sends the mail. simpleEmail.send(); }
From source file:org.xaloon.wicket.component.email.EmailFacadeImpl.java
public void sendEmail(EmailTemplate template, String emailContent, String fromEmail, String fromName) { try {/*from w w w . j a v a 2 s.c om*/ SimpleEmail email = new SimpleEmail(); email.setDebug(false); email.setHostName(template.getHostName()); email.setCharset(template.getCharset()); email.addTo(template.getToEmail(), template.getName()); email.setFrom(fromEmail, fromName); email.setSubject(template.getSubject()); email.setContent(emailContent, "text/html; charset=" + "UTF-8"); email.send(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.xaloon.wicket.plugin.email.DefaultEmailService.java
private boolean sendEmailInternal(String emailContent, String subject, String fromEmail, String fromName, String toEmail, String toName) { EmailPluginBean emailPluginBean = getPluginBean(); SimpleEmail email = new SimpleEmail(); email.setDebug(emailPluginBean.isDebug()); email.setHostName(emailPluginBean.getHost()); email.setSmtpPort(emailPluginBean.getPort()); if (emailPluginBean.isRequiresAuthentication()) { email.setAuthentication(emailPluginBean.getUsername(), emailPluginBean.getPassword()); }/* w w w . j a va 2 s . c o m*/ email.setCharset(emailPluginBean.getCharset()); try { email.setTLS(emailPluginBean.isStartTLS()); email.addTo(toEmail, toName); email.setFrom(fromEmail, fromName); email.setSubject(subject); email.setContent(emailContent, "text/html; charset=" + emailPluginBean.getCharset()); email.send(); } catch (Exception e) { LOGGER.error("Message could not be sent!", e); return false; } return true; }