List of usage examples for org.apache.commons.mail Email setSubject
public Email setSubject(final String aSubject)
From source file:org.apache.sling.commons.messaging.mail.internal.SimpleMailBuilder.java
@Override public Email build(@Nonnull final String message, @Nonnull final String recipient, @Nonnull final Map data) throws EmailException { final Map configuration = (Map) data.getOrDefault("mail", Collections.EMPTY_MAP); final String subject = (String) configuration.getOrDefault(SUBJECT_KEY, this.configuration.subject()); final String from = (String) configuration.getOrDefault(FROM_KEY, this.configuration.from()); final String charset = (String) configuration.getOrDefault(CHARSET_KEY, this.configuration.charset()); final String smtpHostname = (String) configuration.getOrDefault(SMTP_HOSTNAME_KEY, this.configuration.smtpHostname()); final int smtpPort = (Integer) configuration.getOrDefault(SMTP_PORT_KEY, this.configuration.smtpPort()); final String smtpUsername = (String) configuration.getOrDefault(SMTP_USERNAME_KEY, this.configuration.smtpUsername()); final String smtpPassword = (String) configuration.getOrDefault(SMTP_PASSWORD_KEY, this.configuration.smtpPassword()); final Email email = new SimpleEmail(); email.setCharset(charset);// ww w.j a va2s. co m email.setMsg(message); email.addTo(recipient); email.setSubject(subject); email.setFrom(from); email.setHostName(smtpHostname); email.setSmtpPort(smtpPort); email.setAuthentication(smtpUsername, smtpPassword); return email; }
From source file:org.apache.wookie.helpers.WidgetKeyManager.java
/** * Send email.//from w w w . j a v a 2 s . c o m * * @param mailserver - the SMTP mail server address * @param from * @param to * @param message * @throws Exception */ private static void sendEmail(String mailserver, int port, String from, String to, String message, String username, String password) throws EmailException { Email email = new SimpleEmail(); email.setDebug(false); // true if you want to debug email.setHostName(mailserver); if (username != null) { email.setAuthentication(username, password); email.getMailSession().getProperties().put("mail.smtp.starttls.enable", "true"); } email.setFrom(from, "Wookie Server"); email.setSubject("Wookie API Key"); email.setMsg(message); email.addTo(to); email.send(); }
From source file:org.camunda.bpm.example.coffee.service.SendMailTask.java
private void sendMail(String to) throws EmailException { String host = mailProperties.getProperty("host"); Integer port = Integer.valueOf(mailProperties.getProperty("port")); String user = mailProperties.getProperty("user"); String password = mailProperties.getProperty("password"); String from = mailProperties.getProperty("from"); Email email = new SimpleEmail(); email.setHostName(host);/* w ww . ja va 2s . c om*/ email.setTLS(true); email.setSmtpPort(port); email.setAuthentication(user, password); email.setFrom(from); email.setSubject("Your Coffee"); email.setMsg("...is ready to drink."); email.addTo(to); getMailProvider().send(email); }
From source file:org.camunda.bpm.quickstart.TaskAssignmentListener.java
public void notify(DelegateTask delegateTask) { String assignee = delegateTask.getAssignee(); String taskId = delegateTask.getId(); if (assignee != null) { // Get User Profile from User Management IdentityService identityService = Context.getProcessEngineConfiguration().getIdentityService(); User user = identityService.createUserQuery().userId(assignee).singleResult(); if (user != null) { // Get Email Address from User Profile String recipient = user.getEmail(); if (recipient != null && !recipient.isEmpty()) { Email email = new SimpleEmail(); email.setCharset("utf-8"); email.setHostName(HOST); email.setAuthentication(USER, PWD); try { email.setFrom("noreply@camunda.org"); email.setSubject("Task assigned: " + delegateTask.getName()); email.setMsg("Please complete: http://localhost:8080/camunda/app/tasklist/default/#/task/" + taskId);/* w w w. j a va 2 s. c om*/ email.addTo(recipient); email.send(); LOGGER.info("Task Assignment Email successfully sent to user '" + assignee + "' with address '" + recipient + "'."); } catch (Exception e) { LOGGER.log(Level.WARNING, "Could not send email to assignee", e); } } else { LOGGER.warning("Not sending email to user " + assignee + "', user has no email address."); } } else { LOGGER.warning( "Not sending email to user " + assignee + "', user is not enrolled with identity service."); } } }
From source file:org.chenillekit.mail.services.impl.MailServiceImpl.java
private void setMailMessageHeaders(Email email, MailMessageHeaders headers) throws EmailException { email.setFrom(headers.getFrom());//from w w w . j a v a2 s .c o m try { email.setSubject(MimeUtility.encodeText(headers.getSubject(), headers.getCharset(), null)); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } for (String to : headers.getTo()) { email.addTo(to); } for (String cc : headers.getCc()) { email.addCc(cc); } for (String bcc : headers.getBcc()) { email.addBcc(bcc); } }
From source file:org.cobbzilla.mail.sender.SmtpMailSender.java
@Override public void send(SimpleEmailMessage message) throws EmailException { Email email = constructEmail(message); email.setHostName(config.getHost()); email.setSmtpPort(config.getPort()); if (config.getHasMailUser()) { email.setAuthenticator(new DefaultAuthenticator(config.getUser(), config.getPassword())); }/* w ww . j av a2 s . c om*/ email.setTLS(config.isTlsEnabled()); email.setSubject(message.getSubject()); if (message.getToName() != null) { email.addTo(message.getToEmail(), message.getToName()); } else { email.addTo(message.getToEmail()); } if (message.getBcc() != null) { email.addBcc(message.getBcc()); } if (message.getCc() != null) { email.addCc(message.getCc()); } if (message.getFromName() != null) { email.setFrom(message.getFromEmail(), message.getFromName()); } else { email.setFrom(message.getFromEmail()); } sendEmail_internal(email); }
From source file:org.dllearner.algorithms.qtl.experiments.PRConvergenceExperiment.java
private void sendFinishedMail() throws EmailException, IOException { Properties config = new Properties(); config.load(Thread.currentThread().getContextClassLoader() .getResourceAsStream("org/dllearner/algorithms/qtl/qtl-mail.properties")); Email email = new SimpleEmail(); email.setHostName(config.getProperty("hostname")); email.setSmtpPort(465);//from w w w . jav a2 s . co m email.setAuthenticator( new DefaultAuthenticator(config.getProperty("username"), config.getProperty("password"))); email.setSSLOnConnect(true); email.setFrom(config.getProperty("from")); email.setSubject("QTL evaluation finished."); email.setMsg("QTL evaluation finished."); email.addTo(config.getProperty("to")); email.send(); }
From source file:org.fao.geonet.util.MailUtil.java
/** * Send a plain text mail. Will look on the settings directly to know the * remitent//from ww w . j av a2s.c o m * * @param toAddress * @param subject * @param message * @param settings * @throws EmailException */ public static Boolean sendMail(List<String> toAddress, String subject, String message, SettingManager settings) { // Create data information to compose the mail Email email = new SimpleEmail(); configureBasics(settings, email); email.setSubject(subject); try { email.setMsg(message); } catch (EmailException e1) { Log.error(LOG_MODULE_NAME, "Error setting email 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 send(email); }
From source file:org.fao.geonet.util.MailUtil.java
/** * Send a plain text mail. Will look on the settings directly to know the * remitent//from w w w . j a va2 s . c o m * * @param toAddress * @param subject * @param message * @param htmlMessage * @param settings * @param replyTo * @param replyToDesc @throws EmailException */ public static Boolean sendMail(List<String> toAddress, String subject, String message, String htmlMessage, SettingManager settings, String replyTo, String replyToDesc) { // Create data information to compose the mail boolean isHtml = StringUtils.isNotBlank(htmlMessage); Email email = isHtml ? new HtmlEmail() : new SimpleEmail(); configureBasics(settings, email); List<InternetAddress> addressColl = new ArrayList<InternetAddress>(); if (StringUtils.isNotEmpty(replyTo)) { try { addressColl.add(new InternetAddress(replyTo, replyToDesc)); email.setReplyTo(addressColl); } catch (UnsupportedEncodingException e2) { Log.error(LOG_MODULE_NAME, "Error setting email replyTo. Characters not supported in \"" + replyToDesc + "\"", e2); return false; } catch (EmailException e) { Log.error(LOG_MODULE_NAME, "Error setting email replyTo. Invalid email address \"" + replyTo + "\"", e); return false; } } email.setSubject(subject); try { if (StringUtils.isNotBlank(message)) { email.setMsg(message); } if (isHtml) { ((HtmlEmail) email).setHtmlMsg(htmlMessage); } } catch (EmailException e1) { Log.error(LOG_MODULE_NAME, "Error setting email 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 send(email); }
From source file:org.fao.geonet.util.MailUtil.java
/** * Send a plain text mail/*from w ww. j a v a 2s. c o m*/ * * @param toAddress * @param from * @param subject * @param message * @throws EmailException */ public static Boolean sendMail(List<String> toAddress, String from, String subject, String message, SettingManager settings) { Email email = new SimpleEmail(); 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); email.setSubject(subject); try { email.setMsg(message); } catch (EmailException e1) { Log.error(LOG_MODULE_NAME, "Error setting email 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); }