List of usage examples for org.apache.commons.mail Email setSubject
public Email setSubject(final String aSubject)
From source file:com.packtpub.e4.advanced.event.mailman.MailSender.java
@Override public void handleEvent(Event event) { String topic = event.getTopic(); if (topic.startsWith("smtp/")) { String importance = topic.substring("smtp/".length()); String to = (String) event.getProperty("To"); String from = (String) event.getProperty("From"); String subject = (String) event.getProperty("Subject"); String body = (String) event.getProperty("DATA"); try {//from w ww.j a va 2s . c o m Email email = new SimpleEmail(); email.setDebug(false); email.setHostName(hostname); email.setSmtpPort(port); email.setFrom(from); email.addTo(to); email.setSubject(subject); email.setMsg(body); email.addHeader("Importance", importance); email.send(); log(LogService.LOG_INFO, "Message sent successfully to " + to); } catch (EmailException e) { log(LogService.LOG_ERROR, "Error occurred" + e); } } }
From source file:com.kylinolap.job.tools.MailService.java
public void sendMail(List<String> receivers, String subject, String content) throws IOException { Email email = new HtmlEmail(); email.setHostName(host);/*from ww w. j a v a 2 s .c o m*/ email.setDebug(true); try { for (String receiver : receivers) { email.addTo(receiver); } email.setFrom(sender); email.setSubject(subject); email.setCharset("UTF-8"); ((HtmlEmail) email).setHtmlMsg(content); email.send(); email.getMailSession(); System.out.println("!!"); } catch (EmailException e) { e.printStackTrace(); } }
From source file:de.hybris.basecommerce.SimpleSmtpServerUtilsTest.java
@Test public void testSendSuccess() throws EmailException, AddressException { final String origMailPortNumber = Config.getParameter(Config.Params.MAIL_SMTP_PORT); final String origMailHost = Config.getParameter(Config.Params.MAIL_SMTP_SERVER); SimpleSmtpServer server = null;//from w ww . ja v a2 s .c o m try { server = SimpleSmtpServerUtils.startServer(TEST_START_PORT); Assert.assertFalse(server.isStopped()); Assert.assertTrue(server.getPort() > 0); Config.setParameter(Config.Params.MAIL_SMTP_SERVER, "localhost"); Config.setParameter(Config.Params.MAIL_SMTP_PORT, String.valueOf(server.getPort())); final Email email = MailUtils.getPreConfiguredEmail(); email.setFrom("foo.bar@hybris.com"); email.setTo(Arrays.asList(InternetAddress.parse("foo.bar@hybris.com"))); email.setSubject("TEST TEST TEST"); email.setContent("FOO", Email.TEXT_PLAIN); email.send(); } finally { Config.setParameter(Config.Params.MAIL_SMTP_SERVER, origMailHost); Config.setParameter(Config.Params.MAIL_SMTP_PORT, origMailPortNumber); if (server != null) { server.stop(); } } }
From source file:com.intuit.wasabi.email.impl.EmailServiceImpl.java
void send(String subject, String msg, String... to) { String[] clearTo = removeInvalidEmails(to); if (isActive()) { try {//from www . j a va 2 s . c om Email email = createSimpleMailService(); email.setHostName(host); email.setFrom(from); email.setSubject(subjectPrefix + " " + subject); email.setMsg(msg); email.addTo(clearTo); email.send(); } catch (EmailException mailExcp) { LOGGER.error("Email could not be send because of " + mailExcp.getMessage()); throw new WasabiEmailException("Email: " + emailToString(subject, msg, to) + " could not be sent.", mailExcp); } } else { //if the service is not active log the email that would have been send and throw error LOGGER.info("EmailService would have sent: " + emailToString(subject, msg, to)); throw new WasabiEmailException(ErrorCode.EMAIL_NOT_ACTIVE_ERROR, "The EmailService is not active."); } }
From source file:br.com.jvmsoftware.util.EnviarMail.java
public void emailSimples(PubConfigEmpresa conf, PubUsuario usu, String msg, String subj) throws EmailException { Email email = new SimpleEmail(); email.setHostName(conf.getMailEnvioSmtp()); email.setSmtpPort(conf.getMailEnvioPorta()); email.setAuthenticator(new DefaultAuthenticator(conf.getMailEnvio(), conf.getMailEnvioSenha())); email.setSSLOnConnect(true);//from ww w . j a va2s. c o m email.setFrom(conf.getMailEnvio()); email.setSubject(subj); email.setMsg(msg); email.addTo(usu.getEmail()); email.send(); }
From source file:gov.nih.nci.firebird.service.messages.email.EmailServiceImpl.java
private Email prepareSimpleMessage(Collection<String> to, Collection<String> cc, FirebirdMessage message) throws EmailException { Email email = new SimpleEmail(); email.setSentDate(new Date()); email.setSubject(message.getSubject()); if (StringUtils.isBlank(overrideEmailAddress)) { addToAddresses(email, to);// w w w. j av a 2 s . co m addCcAddresses(email, cc); email.setMsg(message.getBody()); } else { email.addTo(overrideEmailAddress); email.setMsg(buildOverriddenEmailBody(to, cc, message)); } return email; }
From source file:gobblin.util.EmailUtils.java
/** * A general method for sending emails.// w ww . j a va2 s . c om * * @param state a {@link State} object containing configuration properties * @param subject email subject * @param message email message * @throws EmailException if there is anything wrong sending the email */ public static void sendEmail(State state, String subject, String message) throws EmailException { Email email = new SimpleEmail(); email.setHostName(state.getProp(ConfigurationKeys.EMAIL_HOST_KEY, ConfigurationKeys.DEFAULT_EMAIL_HOST)); if (state.contains(ConfigurationKeys.EMAIL_SMTP_PORT_KEY)) { email.setSmtpPort(state.getPropAsInt(ConfigurationKeys.EMAIL_SMTP_PORT_KEY)); } email.setFrom(state.getProp(ConfigurationKeys.EMAIL_FROM_KEY)); if (state.contains(ConfigurationKeys.EMAIL_USER_KEY) && state.contains(ConfigurationKeys.EMAIL_PASSWORD_KEY)) { email.setAuthentication(state.getProp(ConfigurationKeys.EMAIL_USER_KEY), PasswordManager .getInstance(state).readPassword(state.getProp(ConfigurationKeys.EMAIL_PASSWORD_KEY))); } Iterable<String> tos = Splitter.on(',').trimResults().omitEmptyStrings() .split(state.getProp(ConfigurationKeys.EMAIL_TOS_KEY)); for (String to : tos) { email.addTo(to); } String hostName; try { hostName = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException uhe) { LOGGER.error("Failed to get the host name", uhe); hostName = "unknown"; } email.setSubject(subject); String fromHostLine = String.format("This email was sent from host: %s%n%n", hostName); email.setMsg(fromHostLine + message); email.send(); }
From source file:com.cognifide.qa.bb.email.EmailSender.java
public void sendEmail(final EmailData emailData) { try {/* w ww. ja v a 2 s. com*/ Email email = new SimpleEmail(); email.setHostName(smtpServer); email.setSmtpPort(smtpPort); email.setAuthenticator(new DefaultAuthenticator(username, password)); email.setSSLOnConnect(secure); email.setFrom(emailData.getAddressFrom()); email.setSubject(emailData.getSubject()); email.setMsg(emailData.getMessageContent()); email.addTo(emailData.getAddressTo()); email.send(); } catch (org.apache.commons.mail.EmailException e) { throw new EmailException(e); } }
From source file:com.music.service.EmailService.java
@Async public void send(EmailDetails details) { if (details.getSubject() == null || !BooleanUtils .xor(ArrayUtils.toArray(details.getMessage() != null, details.getMessageTemplate() != null))) { throw new IllegalStateException( "Either subject or subjectKey / either template/message/messageKey should be specified"); }//www. j a v a2s . co m Validate.notBlank(details.getFrom()); Email email = createEmail(details.isHtml()); String subject = constructSubject(details); email.setSubject(subject); String emailMessage = constructEmailMessages(details); try { if (details.isHtml()) { ((HtmlEmail) email).setHtmlMsg(emailMessage); } else { email.setMsg(emailMessage); } for (String to : details.getTo()) { email.addTo(to); } email.setFrom(details.getFrom()); email.send(); } catch (EmailException ex) { logger.error("Exception occurred when sending email to " + details.getTo(), ex); } }
From source file:com.pronoiahealth.olhie.server.services.MailSendingService.java
/** * Sends a password reset email to the email address provided * /*from ww w. j a v a 2s . c o m*/ * @param toEmail * @param newPwd * @throws Exception */ public void sendPwdResetMailFromApp(String toEmail, String newPwd) throws Exception { Email email = new SimpleEmail(); email.setSmtpPort(Integer.parseInt(smtpPort)); email.setAuthenticator(new DefaultAuthenticator(fromAddress, fromPwd)); email.setDebug(Boolean.parseBoolean(debugEnabled)); email.setHostName(smtpSever); email.setFrom(fromAddress); email.setSubject("Reset Olhie Password"); email.setMsg("You have requested that your password be reset. Your new Olhie password is " + newPwd); email.addTo(toEmail); email.setTLS(Boolean.parseBoolean(tlsEnabled)); email.setSocketTimeout(10000); email.setSocketConnectionTimeout(12000); email.send(); }