List of usage examples for org.apache.commons.mail SimpleEmail setTo
public Email setTo(final Collection<InternetAddress> aCollection) throws EmailException
From source file:com.adobe.acs.commons.hc.impl.SMTPMailServiceHealthCheck.java
@Override @SuppressWarnings("squid:S1141") public Result execute() { final FormattingResultLog resultLog = new FormattingResultLog(); if (messageGatewayService == null) { resultLog.critical("MessageGatewayService OSGi service could not be found."); resultLog.info(/*from w ww .j av a 2s. co m*/ "Verify the Default Mail Service is active: http://<host>:<port>/system/console/components/com.day.cq.mailer.impl.CqMailingService"); } else { final MessageGateway<SimpleEmail> messageGateway = messageGatewayService.getGateway(SimpleEmail.class); if (messageGateway == null) { resultLog.critical("The AEM Default Mail Service is INACTIVE, thus e-mails cannot be sent."); resultLog.info( "Verify the Default Mail Service is active and configured: http://<host>:<port>/system/console/components/com.day.cq.mailer.DefaultMailService"); log.warn("Could not retrieve a SimpleEmail Message Gateway"); } else { try { List<InternetAddress> emailAddresses = new ArrayList<InternetAddress>(); emailAddresses.add(new InternetAddress(this.toEmail)); MailTemplate mailTemplate = new MailTemplate(IOUtils.toInputStream(MAIL_TEMPLATE), CharEncoding.UTF_8); SimpleEmail email = mailTemplate.getEmail(StrLookup.mapLookup(Collections.emptyMap()), SimpleEmail.class); email.setSubject("AEM E-mail Service Health Check"); email.setTo(emailAddresses); email.setSocketConnectionTimeout(TIMEOUT); email.setSocketTimeout(TIMEOUT); try { messageGateway.send(email); resultLog.info( "The E-mail Service appears to be working properly. Verify the health check e-mail was sent to [ {} ]", this.toEmail); } catch (Exception e) { resultLog.critical( "Failed sending e-mail. Unable to send a test toEmail via the configured E-mail server: " + e.getMessage(), e); log.warn("Failed to send E-mail for E-mail Service health check", e); } logMailServiceConfig(resultLog, email); } catch (Exception e) { resultLog.healthCheckError( "Sling Health check could not formulate a test toEmail: " + e.getMessage(), e); log.error("Unable to execute E-mail health check", e); } } } return new Result(resultLog); }
From source file:com.mycompany.apps.MailService.java
public void doSomeService() { HashMap map = new HashMap(); map.put("name", "hoge"); map.put("today", "2014/11/20"); // ... ?map????? String msg = mailBuilder.buildMessage(map); System.out.println("?:" + msg); try {//from w w w. j ava 2 s . c o m SimpleEmail email = new SimpleEmail(); //?? email.setHostName("localhost"); //?? List to = new ArrayList(); InternetAddress to1 = new InternetAddress("to1@mail.myserver.com"); to.add(to1); InternetAddress to2 = new InternetAddress("to2@mail.myserver.com"); to.add(to2); email.setTo(to); //?? email.setFrom("from@mail.myserver.com"); //? email.addReplyTo("reply@mail.myserver.com"); //?? email.setSubject(""); //?? email.setMsg(msg); //?? // email.send(); } catch (EmailException ex) { ex.printStackTrace(); } catch (AddressException ex) { ex.printStackTrace(); } }
From source file:pl.bcichecki.rms.services.impl.EmailServiceImpl.java
@Override public boolean sendEmail(String title, String content, List<String> recipents) throws ServiceException { SimpleEmail email; try {/* w ww . ja v a 2 s .c om*/ List<InternetAddress> recipentAddresses = new ArrayList<InternetAddress>(); for (String address : recipents) { recipentAddresses.add(new InternetAddress(address)); } email = emailConfiguration.getConfiguredEmail(); email.setTo(recipentAddresses); email.setSubject(title); email.setMsg(content); } catch (EmailException | AddressException ex) { throw new ServiceException("Could not configure email.", "exceptions.serviceExceptions.email.configError", ex); } try { return !StringUtils.isBlank(email.send()); } catch (EmailException ex) { throw new ServiceException("Could not send email.", "exceptions.serviceExceptions.email.sendingError", ex); } }