List of usage examples for org.apache.commons.mail Email setSmtpPort
public void setSmtpPort(final int aPortNumber)
From source file:org.apache.airavata.credential.store.notifier.impl.EmailNotifier.java
public void notifyMessage(NotificationMessage message) throws CredentialStoreException { try {//from w w w.j a v a 2 s . co m Email email = new SimpleEmail(); email.setHostName(this.emailNotifierConfiguration.getEmailServer()); email.setSmtpPort(this.emailNotifierConfiguration.getEmailServerPort()); email.setAuthenticator(new DefaultAuthenticator(this.emailNotifierConfiguration.getEmailUserName(), this.emailNotifierConfiguration.getEmailPassword())); email.setSSLOnConnect(this.emailNotifierConfiguration.isSslConnect()); email.setFrom(this.emailNotifierConfiguration.getFromAddress()); EmailNotificationMessage emailMessage = (EmailNotificationMessage) message; email.setSubject(emailMessage.getSubject()); email.setMsg(emailMessage.getMessage()); email.addTo(emailMessage.getSenderEmail()); email.send(); } catch (EmailException e) { log.error("[CredentialStore]Error sending email notification message."); throw new CredentialStoreException("Error sending email notification message", e); } }
From source file:org.apache.kylin.common.util.MailService.java
/** * @param receivers/* w w w .ja v a2 s . co m*/ * @param subject * @param content * @return true or false indicating whether the email was delivered successfully * @throws IOException */ public boolean sendMail(List<String> receivers, String subject, String content, boolean isHtmlMsg) { if (!enabled) { logger.info("Email service is disabled; this mail will not be delivered: " + subject); logger.info("To enable mail service, set 'kylin.job.notification-enabled=true' in kylin.properties"); return false; } Email email = new HtmlEmail(); email.setHostName(host); email.setStartTLSEnabled(starttlsEnabled); if (starttlsEnabled) { email.setSslSmtpPort(port); } else { email.setSmtpPort(Integer.valueOf(port)); } if (username != null && username.trim().length() > 0) { email.setAuthentication(username, password); } //email.setDebug(true); try { for (String receiver : receivers) { email.addTo(receiver); } email.setFrom(sender); email.setSubject(subject); email.setCharset("UTF-8"); if (isHtmlMsg) { ((HtmlEmail) email).setHtmlMsg(content); } else { ((HtmlEmail) email).setTextMsg(content); } email.send(); email.getMailSession(); } catch (EmailException e) { logger.error(e.getLocalizedMessage(), e); return false; } return true; }
From source file:org.apache.nifi.processors.email.TestListenSMTP.java
@Test public void validateSuccessfulInteraction() throws Exception, EmailException { int port = NetworkUtils.availablePort(); TestRunner runner = TestRunners.newTestRunner(ListenSMTP.class); runner.setProperty(ListenSMTP.SMTP_PORT, String.valueOf(port)); runner.setProperty(ListenSMTP.SMTP_MAXIMUM_CONNECTIONS, "3"); runner.setProperty(ListenSMTP.SMTP_TIMEOUT, "10 seconds"); runner.assertValid();/*w ww . ja va2 s. c o m*/ runner.run(5, false); final int numMessages = 5; CountDownLatch latch = new CountDownLatch(numMessages); this.executor.schedule(new Runnable() { @Override public void run() { for (int i = 0; i < numMessages; i++) { try { Email email = new SimpleEmail(); email.setHostName("localhost"); email.setSmtpPort(port); email.setFrom("alice@nifi.apache.org"); email.setSubject("This is a test"); email.setMsg("MSG-" + i); email.addTo("bob@nifi.apache.org"); email.send(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } finally { latch.countDown(); } } } }, 1500, TimeUnit.MILLISECONDS); boolean complete = latch.await(5000, TimeUnit.MILLISECONDS); runner.shutdown(); assertTrue(complete); runner.assertAllFlowFilesTransferred(ListenSMTP.REL_SUCCESS, numMessages); }
From source file:org.apache.nifi.processors.email.TestListenSMTP.java
@Test public void validateSuccessfulInteractionWithTls() throws Exception, EmailException { System.setProperty("mail.smtp.ssl.trust", "*"); System.setProperty("javax.net.ssl.keyStore", "src/test/resources/localhost-ks.jks"); System.setProperty("javax.net.ssl.keyStorePassword", "localtest"); int port = NetworkUtils.availablePort(); TestRunner runner = TestRunners.newTestRunner(ListenSMTP.class); runner.setProperty(ListenSMTP.SMTP_PORT, String.valueOf(port)); runner.setProperty(ListenSMTP.SMTP_MAXIMUM_CONNECTIONS, "3"); runner.setProperty(ListenSMTP.SMTP_TIMEOUT, "10 seconds"); // Setup the SSL Context SSLContextService sslContextService = new StandardSSLContextService(); runner.addControllerService("ssl-context", sslContextService); runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE, "src/test/resources/localhost-ts.jks"); runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_PASSWORD, "localtest"); runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_TYPE, "JKS"); runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE, "src/test/resources/localhost-ks.jks"); runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE_PASSWORD, "localtest"); runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE_TYPE, "JKS"); runner.enableControllerService(sslContextService); // and add the SSL context to the runner runner.setProperty(ListenSMTP.SSL_CONTEXT_SERVICE, "ssl-context"); runner.setProperty(ListenSMTP.CLIENT_AUTH, SSLContextService.ClientAuth.NONE.name()); runner.assertValid();/* w ww. ja v a 2 s . c om*/ int messageCount = 5; CountDownLatch latch = new CountDownLatch(messageCount); runner.run(messageCount, false); this.executor.schedule(new Runnable() { @Override public void run() { for (int i = 0; i < messageCount; i++) { try { Email email = new SimpleEmail(); email.setHostName("localhost"); email.setSmtpPort(port); email.setFrom("alice@nifi.apache.org"); email.setSubject("This is a test"); email.setMsg("MSG-" + i); email.addTo("bob@nifi.apache.org"); // Enable STARTTLS but ignore the cert email.setStartTLSEnabled(true); email.setStartTLSRequired(true); email.setSSLCheckServerIdentity(false); email.send(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } finally { latch.countDown(); } } } }, 1500, TimeUnit.MILLISECONDS); boolean complete = latch.await(5000, TimeUnit.MILLISECONDS); runner.shutdown(); assertTrue(complete); runner.assertAllFlowFilesTransferred("success", messageCount); }
From source file:org.apache.nifi.processors.email.TestListenSMTP.java
@Test public void validateTooLargeMessage() throws Exception, EmailException { int port = NetworkUtils.availablePort(); TestRunner runner = TestRunners.newTestRunner(ListenSMTP.class); runner.setProperty(ListenSMTP.SMTP_PORT, String.valueOf(port)); runner.setProperty(ListenSMTP.SMTP_MAXIMUM_CONNECTIONS, "3"); runner.setProperty(ListenSMTP.SMTP_TIMEOUT, "10 seconds"); runner.setProperty(ListenSMTP.SMTP_MAXIMUM_MSG_SIZE, "10 B"); runner.assertValid();//ww w . ja va 2 s . c o m int messageCount = 1; CountDownLatch latch = new CountDownLatch(messageCount); runner.run(messageCount, false); this.executor.schedule(new Runnable() { @Override public void run() { for (int i = 0; i < messageCount; i++) { try { Email email = new SimpleEmail(); email.setHostName("localhost"); email.setSmtpPort(port); email.setFrom("alice@nifi.apache.org"); email.setSubject("This is a test"); email.setMsg("MSG-" + i); email.addTo("bob@nifi.apache.org"); email.send(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } finally { latch.countDown(); } } } }, 1000, TimeUnit.MILLISECONDS); boolean complete = latch.await(5000, TimeUnit.MILLISECONDS); runner.shutdown(); assertTrue(complete); runner.assertAllFlowFilesTransferred("success", 0); }
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);/*from w w w.ja va 2 s . 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.camunda.bpm.engine.impl.bpmn.behavior.MailActivityBehavior.java
protected void setMailServerProperties(Email email) { ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration(); String host = processEngineConfiguration.getMailServerHost(); if (host == null) { throw new ProcessEngineException("Could not send email: no SMTP host is configured"); }/*from w w w . j av a2s .c om*/ email.setHostName(host); int port = processEngineConfiguration.getMailServerPort(); email.setSmtpPort(port); email.setTLS(processEngineConfiguration.getMailServerUseTLS()); String user = processEngineConfiguration.getMailServerUsername(); String password = processEngineConfiguration.getMailServerPassword(); if (user != null && password != null) { email.setAuthentication(user, password); } }
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);/*from ww w.jav a 2 s .co m*/ 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.chenillekit.mail.services.impl.MailServiceImpl.java
private void setEmailStandardData(Email email) { email.setHostName(smtpServer);/*from w w w .ja v a 2s . com*/ if (smtpUser != null && smtpUser.length() > 0) email.setAuthentication(smtpUser, smtpPassword); email.setDebug(smtpDebug); email.setSmtpPort(smtpPort); email.setSSL(smtpSSL); email.setSslSmtpPort(String.valueOf(smtpSslPort)); email.setTLS(smtpTLS); }
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())); }/*from ww w. j av a2 s. c o m*/ 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); }