List of usage examples for org.apache.commons.mail Email getSubject
public String getSubject()
From source file:com.bytecode.util.SendEmail.java
static boolean sendADEmail(Email msg) { boolean sent = false; try {/* w ww . ja v a 2 s.c om*/ // Create the email message HtmlEmail email = new HtmlEmail(); email.setHostName("172.16.10.184"); email.setSmtpPort(25); email.addTo(msg.getEmailAddress()); email.setFrom("twofactor@unionbankng.com", "Union Bank"); if (msg.getSubject().equalsIgnoreCase("SPECIAL")) { email.setSubject("MANUAL ACTIVATION"); } else { email.setSubject("Two Factor Authentication Details"); } String formattedEmail = formatEmail(msg.getMessage()); // set the html message email.setHtmlMsg(formattedEmail); // set the alternative message email.setTextMsg("Your email client does not support HTML messages"); // send the email Log.l.infoLog.info("Sending email to " + msg.getEmailAddress()); String response = email.send(); sent = true; Log.l.infoLog.info("Email Sent to :" + msg.getEmailAddress() + " Response:" + response); return sent; } catch (EmailException ex) { Log.l.infoLog.info(ex); return sent; } catch (Exception ex) { Log.l.infoLog.info(ex); return sent; } }
From source file:com.qwazr.library.email.EmailConnectorTest.java
private void checkEmail(final Map<String, Object> params, final Email email) { Assert.assertNotNull(email);// www . j a v a 2s. c om Assert.assertEquals(params.get("subject"), email.getSubject()); Assert.assertEquals(params.get("from_email"), email.getFromAddress().getAddress()); Assert.assertEquals(params.get("from_name"), email.getFromAddress().getPersonal()); }
From source file:ch.sdi.core.impl.mail.MailCreatorTest.java
@Test public void testCreateMailFor() throws Throwable { PropertiesPerson person = new PropertiesPerson("person", myPersonProps); Email email = myClassUnderTest.createMailFor(person); myLog.debug("Created Mail: " + email); Assert.assertNotNull(email);//from w ww.j a va 2s .com Assert.assertEquals(THIS_IS_THE_SUBJECT, email.getSubject()); Object content = Whitebox.getInternalState(email, "content"); Assert.assertNotNull(content); Assert.assertEquals(THIS_IS_THE_BODY, content); List<InternetAddress> addresses = email.getToAddresses(); Assert.assertNotNull(addresses); Assert.assertEquals(1, addresses.size()); }
From source file:com.bytecode.util.SendEmail.java
public void sendSimpleMail(Email msg) { // Create The Email MultiPartEmail email = new MultiPartEmail(); try {// w w w .j a v a2 s . c o m email.setHostName("webmail.firmuscap.com"); email.setSmtpPort(25); email.setAuthenticator(new DefaultAuthenticator("alert@firmuscap.com", "Admin100$")); email.setFrom("alert@firmuscap.com"); email.setSubject(msg.getSubject()); email.setMsg(msg.getMessage()); email.addTo(msg.getEmailAddress()); // email.setTLS(true); System.out.println("**************"); email.send(); System.out.println("**************"); } catch (EmailException ee) { ee.printStackTrace(); } }
From source file:com.github.triceo.robozonky.notifications.email.AbstractEmailingListener.java
@Override public void handle(final T event) { if (!this.shouldSendEmail(event)) { LOGGER.debug("Will not send e-mail."); return;//www . j a va 2s . c om } else try { final Email email = AbstractEmailingListener.createNewEmail(properties); email.setSubject(this.getSubject(event)); email.setMsg(TemplateProcessor.INSTANCE.process(this.getTemplateFileName(), this.getData(event))); LOGGER.debug("Will send '{}' from {} to {} through {}:{} as {}.", email.getSubject(), email.getFromAddress(), email.getToAddresses(), email.getHostName(), email.getSmtpPort(), properties.getSmtpUsername()); email.send(); emailsOfThisType.increase(); this.properties.getGlobalCounter().increase(); } catch (final Exception ex) { throw new RuntimeException("Failed processing event.", ex); } }
From source file:com.cm.util.SendEmail.java
public void sendSimpleMail(Email msg) { // Create The Email MultiPartEmail email = new MultiPartEmail(); try {//from w ww. j a v a 2s . c om email.setHostName("mail.icontrolmanager.com"); email.setSmtpPort(25); email.setAuthenticator( new DefaultAuthenticator("corporatematter@icontrolmanager.com", "CorporateMatter1)")); email.setFrom("corporatematter@icontrolmanager.com"); email.setSubject(msg.getSubject()); email.setMsg(msg.getMessage()); email.addTo(msg.getEmailAddress()); // email.setTLS(true); System.out.println("**************"); email.send(); System.out.println("**************"); } catch (EmailException ee) { ee.printStackTrace(); } }
From source file:io.mapzone.controller.email.EmailService.java
public void send(Email email) throws EmailException { String env = System.getProperty("io.mapzone.controller.SMTP"); if (env == null) { throw new IllegalStateException( "Environment variable missing: io.mapzone.controller.SMTPP. Format: <host>|<login>|<passwd>|<from>"); }//from w w w . ja v a2 s.c o m String[] parts = StringUtils.split(env, "|"); if (parts.length < 3 || parts.length > 4) { throw new IllegalStateException( "Environment variable wrong: io.mapzone.controller.SMTP. Format: <host>|<login>|<passwd>|<from> : " + env); } email.setDebug(true); email.setHostName(parts[0]); //email.setSmtpPort( 465 ); //email.setSSLOnConnect( true ); email.setAuthenticator(new DefaultAuthenticator(parts[1], parts[2])); if (email.getFromAddress() == null && parts.length == 4) { email.setFrom(parts[3]); } if (email.getSubject() == null) { throw new EmailException("Missing subject."); } email.send(); }
From source file:adams.core.net.SimpleApacheSendEmail.java
/** * Sends an email./*from w w w. ja v a 2 s . co m*/ * * @param email the email to send * @return true if successfully sent * @throws Exception in case of invalid internet addresses or messaging problem */ @Override public boolean sendMail(Email email) throws Exception { org.apache.commons.mail.Email mail; String id; MultiPartEmail mpemail; EmailAttachment attachment; if (email.getAttachments().length > 0) { mail = new MultiPartEmail(); mpemail = (MultiPartEmail) mail; for (File file : email.getAttachments()) { attachment = new EmailAttachment(); attachment.setPath(file.getAbsolutePath()); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setName(file.getName()); mpemail.attach(attachment); } } else { mail = new SimpleEmail(); } mail.setFrom(email.getFrom().getValue()); for (EmailAddress address : email.getTo()) mail.addTo(address.getValue()); for (EmailAddress address : email.getCC()) mail.addCc(address.getValue()); for (EmailAddress address : email.getBCC()) mail.addBcc(address.getValue()); mail.setSubject(email.getSubject()); mail.setMsg(email.getBody()); mail.setHostName(m_Server); mail.setSmtpPort(m_Port); mail.setStartTLSEnabled(m_UseTLS); mail.setSSLOnConnect(m_UseSSL); if (m_RequiresAuth) mail.setAuthentication(m_User, m_Password.getValue()); mail.setSocketTimeout(m_Timeout); try { id = mail.send(); if (isLoggingEnabled()) getLogger().info("Message sent: " + id); } catch (Exception e) { getLogger().log(Level.SEVERE, "Failed to send email: " + mail, e); return false; } return true; }
From source file:org.apache.isis.example.domainservice.email.EmailService.java
public void send(Email emailObject) { String smtpHost = getContainer().getProperty(PROPERTY_ROOT + "host", "localhost"); String portValue = getContainer().getProperty(PROPERTY_ROOT + "port", "25"); int port = Integer.valueOf(portValue).intValue(); String authenticationName = getContainer().getProperty(PROPERTY_ROOT + "authentication.name"); String authenticationPassword = getContainer().getProperty(PROPERTY_ROOT + "authentication.password", ""); String fromName = getContainer().getProperty(PROPERTY_ROOT + "from.name", "No reply"); String fromEmailAddress = getContainer().getProperty(PROPERTY_ROOT + "from.address", "noreply@domain.com"); try {/* w ww . j a va 2s.co m*/ SimpleEmail simpleEmail = new SimpleEmail(); simpleEmail.setHostName(smtpHost); simpleEmail.setSmtpPort(port); if (authenticationName != null) { simpleEmail.setAuthentication(authenticationName, authenticationPassword); } for (Address address : emailObject.getTo()) { String name = address.getName(); if (name == null) { simpleEmail.addTo(address.getEmailAddress()); } else { simpleEmail.addTo(address.getEmailAddress(), name); } } Address from = emailObject.getFrom(); if (from == null) { simpleEmail.setFrom(fromEmailAddress, fromName); } else { simpleEmail.setFrom(from.getEmailAddress(), from.getName()); } simpleEmail.setSubject(emailObject.getSubject()); simpleEmail.setMsg(emailObject.getMessage()); simpleEmail.send(); } catch (EmailException e) { throw new org.apache.isis.example.domainservice.email.EmailException(e.getMessage(), e); } }
From source file:org.apache.isis.service.email.EmailService.java
public void send(Email emailObject) { String smtpHost = getContainer().getProperty(PROPERTY_ROOT + "host", "localhost"); String portValue = getContainer().getProperty(PROPERTY_ROOT + "port", "25"); int port = Integer.valueOf(portValue).intValue(); String authenticationName = getContainer().getProperty(PROPERTY_ROOT + "authentication.name"); String authenticationPassword = getContainer().getProperty(PROPERTY_ROOT + "authentication.password", ""); String fromName = getContainer().getProperty(PROPERTY_ROOT + "from.name", "No reply"); String fromEmailAddress = getContainer().getProperty(PROPERTY_ROOT + "from.address", "noreply@domain.com"); try {/*from w ww. ja v a2 s .c o m*/ SimpleEmail simpleEmail = new SimpleEmail(); simpleEmail.setHostName(smtpHost); simpleEmail.setSmtpPort(port); if (authenticationName != null) { simpleEmail.setAuthentication(authenticationName, authenticationPassword); } for (Address address : emailObject.getTo()) { String name = address.getName(); if (name == null) { simpleEmail.addTo(address.getEmailAddress()); } else { simpleEmail.addTo(address.getEmailAddress(), name); } } Address from = emailObject.getFrom(); if (from == null) { simpleEmail.setFrom(fromEmailAddress, fromName); } else { simpleEmail.setFrom(from.getEmailAddress(), from.getName()); } simpleEmail.setSubject(emailObject.getSubject()); simpleEmail.setMsg(emailObject.getMessage()); simpleEmail.send(); } catch (EmailException e) { throw new org.apache.isis.service.email.EmailException(e.getMessage(), e); } }