mailType = this.getMailType(templatePath); final MessageGateway<Email> messageGateway = messageGatewayService.getGateway(mailType);
@Override public List<InternetAddress> sendEmail(final String templatePath, final Map<String, String> emailParams, final InternetAddress... recipients) { List<InternetAddress> failureList = new ArrayList<InternetAddress>(); if (recipients == null || recipients.length <= 0) { throw new IllegalArgumentException(MSG_INVALID_RECIPIENTS); } final MailTemplate mailTemplate = this.getMailTemplate(templatePath); final Class<? extends Email> mailType = this.getMailType(templatePath); final MessageGateway<Email> messageGateway = messageGatewayService.getGateway(mailType); for (final InternetAddress address : recipients) { try { // Get a new email per recipient to avoid duplicate attachments final Email email = getEmail(mailTemplate, mailType, emailParams); email.setTo(Collections.singleton(address)); messageGateway.send(email); } catch (Exception e) { failureList.add(address); log.error("Error sending email to [ " + address + " ]", e); } } return failureList; }
mailType = this.getMailType(templatePath); final MessageGateway<Email> messageGateway = messageGatewayService.getGateway(mailType);
@Override public List<InternetAddress> sendEmail(final String templatePath, final Map<String, String> emailParams, final InternetAddress... recipients) { List<InternetAddress> failureList = new ArrayList<InternetAddress>(); if (recipients == null || recipients.length <= 0) { throw new IllegalArgumentException("Invalid Recipients"); } final MailTemplate mailTemplate = this.getMailTemplate(templatePath); final Class<? extends Email> mailType = this.getMailType(templatePath); final MessageGateway<Email> messageGateway = messageGatewayService.getGateway(mailType); for (final InternetAddress address : recipients) { try { // Get a new email per recipient to avoid duplicate attachments final Email email = getEmail(mailTemplate, mailType, emailParams); email.setTo(Collections.singleton(address)); messageGateway.send(email); } catch (Exception e) { failureList.add(address); log.error("Error sending email to [ " + address + " ]", e); } } return failureList; }
resultLog.info("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.");
"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.");
ValueMap props = ResourceUtil.getValueMap(resource); HtmlEmail email = new HtmlEmail(); String[] mailTo = props.get("mailto", new String[0]); email.setFrom((String)props.get("from")); for (String toAddr : mailTo) { email.addTo(toAddr); } //========Email Attachments=============== for (Map.Entry<String, RequestParameter[]> param : slingRequest.getRequestParameterMap().entrySet()) { RequestParameter rpm = param.getValue()[0]; if(!rpm.isFormField()) { EmailAttachment attachment = new EmailAttachment(); attachment.setPath(rpm.getFileName()); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("Any Description"); attachment.setName("Any name you can set"); email.embed(new ByteArrayDataSource(rpm.get(), rpm.getContentType()), rpm.getFileName()); } } //========Email Attachment END=========== String emailTextToSend = "<p>Name: " + slingRequest.getParameter("name") + "</p>"; emailTextToSend += "<p>Message: " + slingRequest.getParameter("message") + "</p>"; email.setHtmlMsg(emailTextToSend); email.setSubject((String)props.get("subject")); MessageGatewayService messageGatewayService = sling.getService(MessageGatewayService.class); MessageGateway messageGateway = messageGatewayService.getGateway(HtmlEmail.class); messageGateway.send(email);