Java Code Examples for org.apache.commons.mail.SimpleEmail
The following examples show how to use
org.apache.commons.mail.SimpleEmail.
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: minsx-framework Author: MinsxCloud File: MailSenderDefaultImpl.java License: Apache License 2.0 | 7 votes |
public void finishInitial() { try { Integer sslPort = 465; simpleEmail = new SimpleEmail(); simpleEmail.setHostName(this.host); simpleEmail.setSmtpPort(this.port); simpleEmail.setAuthentication(this.username, this.password); simpleEmail.setFrom(this.from); simpleEmail.setCharset("UTF-8"); if (sslPort.equals(this.port)) { simpleEmail.setSSLOnConnect(true); } htmlEmail = new HtmlEmail(); htmlEmail.setHostName(this.host); htmlEmail.setSmtpPort(this.port); htmlEmail.setAuthentication(this.username, this.password); htmlEmail.setFrom(this.from); htmlEmail.setCharset("UTF-8"); if (sslPort.equals(this.port)) { htmlEmail.setSSLOnConnect(true); } } catch (EmailException e) { throw new MailSendException(String.format("Incorrect setting field of [from],cause: %s", e.getMessage()), e); } }
Example #2
Source Project: shop Author: RojerAlone File: MailUtil.java License: GNU General Public License v3.0 | 6 votes |
/** * 发送邮件给指定人,需要主题和内容 * @param user * @param title * @param content */ public static void sendMail(String user, String title, String content) { SimpleEmail email = new SimpleEmail(); email.setCharset("UTF8"); email.setHostName("smtp.163.com"); email.setAuthentication(USERNAME, PASSWORD); try { email.setFrom(USERNAME); email.addTo(user); email.setSubject(title); email.setMsg(content); email.send(); } catch (EmailException e) { e.printStackTrace(); } }
Example #3
Source Project: sAINT Author: tiagorlampert File: SendEmail.java License: BSD 3-Clause "New" or "Revised" License | 6 votes |
public void sendSimpleEmail(String email_to, String subject, String msg) { SimpleEmail email = new SimpleEmail(); try { email.setDebug(debug); email.setHostName(smtp); email.addTo(email_to); email.setFrom(email_from); email.setAuthentication(email_from, email_password); email.setSubject(subject); email.setMsg(msg); email.setSSL(ssl); email.setTLS(tls); email.send(); } catch (EmailException e) { System.out.println(e.getMessage()); } }
Example #4
Source Project: bobcat Author: Cognifide File: EmailSender.java License: Apache License 2.0 | 6 votes |
public void sendEmail(final EmailData emailData) { try { 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); } }
Example #5
Source Project: MaxKey Author: shimingxy File: MailTest.java License: Apache License 2.0 | 6 votes |
public void test() throws Exception { String username="[email protected]"; String password="3&8Ujbnm5hkjhFD"; String smtpHost="smtp.exmail.qq.com"; int port=465; boolean ssl=true; String senderMail="[email protected]"; Email email = new SimpleEmail(); email.setHostName(smtpHost); email.setSmtpPort(port); email.setAuthenticator(new DefaultAuthenticator(username, password)); email.setSSLOnConnect(ssl); email.setFrom(senderMail); email.setSubject("One Time PassWord"); email.setMsg("You Token is "+111+" , it validity in "+5 +" minutes"); email.addTo("[email protected]"); email.send(); }
Example #6
Source Project: gameserver Author: wangqi File: EmailManager.java License: Apache License 2.0 | 6 votes |
/** * Send a verification email to the user's email account if exist. * * @param user */ public void sendNormalEmail(String subject, String content, String[] addresses ) { if ( StringUtil.checkNotEmpty(subject) && StringUtil.checkNotEmpty(content) ) { try { String emailSmtp = GameDataManager.getInstance().getGameDataAsString(GameDataKey.EMAIL_SMTP, "mail.xinqihd.com"); SimpleEmail email = new SimpleEmail(); email.setHostName(emailSmtp); email.setAuthenticator(new DefaultAuthenticator(EMAIL_FROM, "[email protected]")); email.setFrom(EMAIL_FROM); email.setSubject(subject); email.setMsg(content); email.setCharset("GBK"); for ( String address : addresses) { if ( StringUtil.checkNotEmpty(address) ) { email.addTo(address); } } email.send(); } catch (EmailException e) { logger.debug("Failed to send normal email", e); } } }
Example #7
Source Project: gsn Author: LSIR File: EmailService.java License: GNU General Public License v3.0 | 6 votes |
/** * This method cover most of the cases of sending a simple text email. If the email to be sent has to be configured * in a way which is not possible whith the parameters provided (such as html email, or email with attachement, ..), * please use the {@link #sendCustomEmail(org.apache.commons.mail.Email)} method and refer the API * {@see http://commons.apache.org/email/}. * * @param to A set of destination email address of the email. Must contain at least one address. * @param object The subject of the email. * @param message The msg of the email. * @return true if the email has been sent successfully, false otherwise. */ public static boolean sendEmail(ArrayList<String> to, String object, String message) { Email email = new SimpleEmail(); try { email.setSubject(object); email.setMsg(message); if (to != null) for (String _to : to) email.addTo(_to); sendCustomEmail(email); return true; } catch (EmailException e) { logger.warn("Please, make sure that the SMTP server configuration is correct in the file: " + SMTP_FILE); logger.error(e.getMessage(), e); return false; } }
Example #8
Source Project: SpringMVC-Project Author: MartinDai File: EmailUtil.java License: MIT License | 5 votes |
/** * 发送文本邮件 */ public static void sendTextEmail(Authenticator authenticator, String hostName, Tuple2<String, String> fromInfo, List<Tuple2<String, String>> toList, List<Tuple2<String, String>> ccList, String subject, String textContent) throws EmailException { SimpleEmail simpleEmail = buildSimpleEmail(authenticator, hostName, fromInfo, toList, ccList, subject); simpleEmail.setMsg(textContent); simpleEmail.send(); }
Example #9
Source Project: activiti6-boot2 Author: dingziyang File: MailActivityBehavior.java License: Apache License 2.0 | 5 votes |
protected SimpleEmail createTextOnlyEmail(String text) { SimpleEmail email = new SimpleEmail(); try { email.setMsg(text); return email; } catch (EmailException e) { throw new ActivitiException("Could not create text-only email", e); } }
Example #10
Source Project: activiti6-boot2 Author: dingziyang File: MailActivityBehavior.java License: Apache License 2.0 | 5 votes |
protected SimpleEmail createTextOnlyEmail(String text) { SimpleEmail email = new SimpleEmail(); try { email.setMsg(text); return email; } catch (EmailException e) { throw new ActivitiException("Could not create text-only email", e); } }
Example #11
Source Project: Android_Code_Arbiter Author: blackarbiter File: InsecureSmtpSsl.java License: GNU Lesser General Public License v3.0 | 5 votes |
public static void main(String[] args) throws Exception { Email email = new SimpleEmail(); email.setHostName("smtp.googlemail.com"); email.setSSLOnConnect(false); //OK Email email2 = new SimpleEmail(); email2.setHostName("smtp2.googlemail.com"); email2.setSSLOnConnect(true); //BAD //email2.setSmtpPort(465); //email2.setAuthenticator(new DefaultAuthenticator("username", "password")); //email2.setFrom("[email protected]"); //email2.setSubject("TestMail"); //email2.setMsg("This is a test mail ... :-)"); //email2.addTo("[email protected]"); //email2.send(); MultiPartEmail emailMulti = new MultiPartEmail(); emailMulti.setHostName("mail.myserver.com"); emailMulti.setSSLOnConnect(true); //BAD HtmlEmail htmlEmail = new HtmlEmail(); htmlEmail.setHostName("mail.myserver.com"); htmlEmail.setSSLOnConnect(true); //BAD ImageHtmlEmail imageEmail = new ImageHtmlEmail(); imageEmail.setHostName("mail.myserver.com"); imageEmail.setSSLOnConnect(true); imageEmail.setSSLCheckServerIdentity(true); //OK ImageHtmlEmail imageEmail2 = new ImageHtmlEmail(); imageEmail2.setHostName("mail2.myserver.com"); imageEmail2.setSSLCheckServerIdentity(true); //OK - reversed order imageEmail2.setSSLOnConnect(true); ImageHtmlEmail imageEmail3 = new ImageHtmlEmail(); imageEmail3.setHostName("mail3.myserver.com"); imageEmail3.setSSLOnConnect(true); //BAD }
Example #12
Source Project: MaxKey Author: shimingxy File: MailOtpAuthn.java License: Apache License 2.0 | 5 votes |
@Override public boolean produce(UserInfo userInfo) { try { String token = this.genToken(userInfo); Email email = new SimpleEmail(); email.setHostName(emailConfig.getSmtpHost()); email.setSmtpPort(emailConfig.getPort()); email.setSSLOnConnect(emailConfig.isSsl()); email.setAuthenticator( new DefaultAuthenticator(emailConfig.getUsername(), emailConfig.getPassword())); email.setFrom(emailConfig.getSender()); email.setSubject(subject); email.setMsg( MessageFormat.format( messageTemplate,userInfo.getUsername(),token,(interval / 60))); email.addTo(userInfo.getEmail()); email.send(); _logger.debug( "token " + token + " send to user " + userInfo.getUsername() + ", email " + userInfo.getEmail()); //成功返回 this.optTokenStore.store( userInfo, token, userInfo.getMobile(), OptTypes.EMAIL); return true; } catch (Exception e) { e.printStackTrace(); } return false; }
Example #13
Source Project: flowable-engine Author: flowable File: MailActivityBehavior.java License: Apache License 2.0 | 5 votes |
protected SimpleEmail createTextOnlyEmail(String text) { SimpleEmail email = new SimpleEmail(); try { email.setMsg(text); return email; } catch (EmailException e) { throw new FlowableException("Could not create text-only email", e); } }
Example #14
Source Project: flowable-engine Author: flowable File: MailActivityBehavior.java License: Apache License 2.0 | 5 votes |
protected SimpleEmail createTextOnlyEmail(String text) { SimpleEmail email = new SimpleEmail(); try { email.setMsg(text); return email; } catch (EmailException e) { throw new FlowableException("Could not create text-only email", e); } }
Example #15
Source Project: flowable-engine Author: flowable File: MailActivityBehavior.java License: Apache License 2.0 | 5 votes |
protected SimpleEmail createTextOnlyEmail(String text) { SimpleEmail email = new SimpleEmail(); try { email.setMsg(text); return email; } catch (EmailException e) { throw new ActivitiException("Could not create text-only email", e); } }
Example #16
Source Project: nexus-public Author: sonatype File: NexusTaskNotificationEmailSender.java License: Eclipse Public License 1.0 | 5 votes |
private void sendEmail(final String subject, final String address, final String body) { try { Email mail = new SimpleEmail(); mail.setSubject(subject); mail.addTo(address); mail.setMsg(body); emailManager.get().send(mail); } catch (Exception e) { log.warn("Failed to send email", e); } }
Example #17
Source Project: nexus-public Author: sonatype File: EmailManagerImpl.java License: Eclipse Public License 1.0 | 5 votes |
@Override public void sendVerification(final EmailConfiguration configuration, final String address) throws EmailException { checkNotNull(configuration); checkNotNull(address); Email mail = new SimpleEmail(); mail.setSubject("Email configuration verification"); mail.addTo(address); mail.setMsg("Verification successful"); mail = apply(configuration, mail); mail.send(); }
Example #18
Source Project: incubator-gobblin Author: apache File: EmailUtils.java License: Apache License 2.0 | 5 votes |
/** * A general method for sending emails. * * @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(); }
Example #19
Source Project: restcommander Author: eBay File: MailTest.java License: Apache License 2.0 | 5 votes |
@Test(expected = MailException.class) public void buildMessageWithoutFrom() throws EmailException { new PlayBuilder().build(); Email email = new SimpleEmail(); email.addTo("[email protected]"); email.setSubject("subject"); Mail.buildMessage(new SimpleEmail()); }
Example #20
Source Project: restcommander Author: eBay File: MailTest.java License: Apache License 2.0 | 5 votes |
@Test(expected = MailException.class) public void buildMessageWithoutRecipient() throws EmailException { new PlayBuilder().build(); Email email = new SimpleEmail(); email.setFrom("[email protected]"); email.setSubject("subject"); Mail.buildMessage(email); }
Example #21
Source Project: restcommander Author: eBay File: MailTest.java License: Apache License 2.0 | 5 votes |
@Test(expected = MailException.class) public void buildMessageWithoutSubject() throws EmailException { new PlayBuilder().build(); Email email = new SimpleEmail(); email.setFrom("[email protected]"); email.addTo("[email protected]"); Mail.buildMessage(email); }
Example #22
Source Project: gsn Author: LSIR File: EmailVirtualSensor.java License: GNU General Public License v3.0 | 5 votes |
public boolean initialize ( ) { TreeMap < String , String > params = getVirtualSensorConfiguration( ).getMainClassInitialParams( ); if(params.get(INITPARAM_SUBJECT) != null) subject = params.get(INITPARAM_SUBJECT); if(params.get(INITPARAM_RECEIVER) != null) receiverEmail = params.get(INITPARAM_RECEIVER); if(params.get(INITPARAM_SENDER) != null) senderEmail = params.get(INITPARAM_SENDER); else { logger.error( "The parameter *" + INITPARAM_SENDER + "* is missing from the virtual sensor processing class's initialization." ); logger.error( "Loading the virtual sensor failed" ); return false; } if(params.get(INITPARAM_SERVER) != null) mailServer = params.get(INITPARAM_SERVER); else { logger.error( "The parameter *" + INITPARAM_SERVER + "* is missing from the virtual sensor processing class's initialization." ); logger.error( "Loading the virtual sensor failed" ); return false; } try { email = new SimpleEmail(); email.setHostName(mailServer); email.setFrom(senderEmail); email.setSubject( subject ); } catch(Exception e) { logger.error( "Email initialization failed", e ); return false; } return true; }
Example #23
Source Project: nifi Author: apache File: GenerateAttachment.java License: Apache License 2.0 | 5 votes |
public MimeMessage SimpleEmailMimeMessage() { Email email = new SimpleEmail(); try { email.setFrom(from); email.addTo(to); email.setSubject(subject); email.setMsg(message); email.setHostName(hostName); email.buildMimeMessage(); } catch (EmailException e) { e.printStackTrace(); } return email.getMimeMessage(); }
Example #24
Source Project: openseedbox Author: openseedbox File: Main.java License: GNU General Public License v3.0 | 5 votes |
public static void testEmail() { try { SimpleEmail se = new SimpleEmail(); se.setFrom("[email protected]"); se.addTo("[email protected]"); se.setSubject("Test email from myseedbox"); se.setMsg("Testy Testy test"); Mail.send(se); } catch (EmailException ex) { resultError(ex.toString()); } result("Yay!"); }
Example #25
Source Project: camunda-bpm-platform Author: camunda File: MailActivityBehavior.java License: Apache License 2.0 | 5 votes |
protected SimpleEmail createTextOnlyEmail(String text) { SimpleEmail email = new SimpleEmail(); try { email.setMsg(text); return email; } catch (EmailException e) { throw LOG.emailCreationException("text-only", e); } }
Example #26
Source Project: SpringMVC-Project Author: MartinDai File: EmailUtil.java License: MIT License | 4 votes |
private static SimpleEmail buildSimpleEmail(Authenticator authenticator, String hostName, Tuple2<String, String> fromInfo, List<Tuple2<String, String>> toList, List<Tuple2<String, String>> ccList, String subject) throws EmailException { SimpleEmail simpleEmail = new SimpleEmail(); return setEmailBaseInfo(simpleEmail, authenticator, hostName, fromInfo, toList, ccList, subject); }
Example #27
Source Project: localization_nifi Author: wangrenlei File: TestListenSMTP.java License: Apache License 2.0 | 4 votes |
@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(); 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("[email protected]"); email.setSubject("This is a test"); email.setMsg("MSG-" + i); email.addTo("[email protected]"); 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); }
Example #28
Source Project: localization_nifi Author: wangrenlei File: TestListenSMTP.java License: Apache License 2.0 | 4 votes |
@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(); 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("[email protected]"); email.setSubject("This is a test"); email.setMsg("MSG-" + i); email.addTo("[email protected]"); // 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); }
Example #29
Source Project: localization_nifi Author: wangrenlei File: TestListenSMTP.java License: Apache License 2.0 | 4 votes |
@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(); 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("[email protected]"); email.setSubject("This is a test"); email.setMsg("MSG-" + i); email.addTo("[email protected]"); 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); }
Example #30
Source Project: minsx-framework Author: MinsxCloud File: MailSenderDefaultImpl.java License: Apache License 2.0 | 4 votes |
public MailSenderDefaultImpl(SimpleEmail simpleEmail) { this.simpleEmail = simpleEmail; }