public void _apply(Email email) throws EmailException { email.setMailSession(helper.getMailSession()); } }
/** * Supply a mail Session object from a JNDI directory. * * @param jndiName name of JNDI resource (javax.mail.Session type), resource * if searched in java:comp/env if name does not start with "java:" * @throws IllegalArgumentException if the JNDI name is null or empty * @throws NamingException if the resource cannot be retrieved from JNDI directory * @since 1.1 */ public void setMailSessionFromJNDI(final String jndiName) throws NamingException { if (EmailUtils.isEmpty(jndiName)) { throw new IllegalArgumentException("JNDI name missing"); } Context ctx = null; if (jndiName.startsWith("java:")) { ctx = new InitialContext(); } else { ctx = (Context) new InitialContext().lookup("java:comp/env"); } this.setMailSession((Session) ctx.lookup(jndiName)); }
/** * Supply a mail Session object from a JNDI directory. * * @param jndiName name of JNDI resource (javax.mail.Session type), resource * if searched in java:comp/env if name does not start with "java:" * @throws IllegalArgumentException if the JNDI name is null or empty * @throws NamingException if the resource cannot be retrieved from JNDI directory * @since 1.1 */ public void setMailSessionFromJNDI(final String jndiName) throws NamingException { if (EmailUtils.isEmpty(jndiName)) { throw new IllegalArgumentException("JNDI name missing"); } Context ctx = null; if (jndiName.startsWith("java:")) { ctx = new InitialContext(); } else { ctx = (Context) new InitialContext().lookup("java:comp/env"); } this.setMailSession((Session) ctx.lookup(jndiName)); }
@Override public Future<Boolean> sendMessage(Email email) { email.setMailSession(Mail.getSession()); return Mail.sendMessage(email); }
/** * This method send a user configured email {@link org.apache.commons.mail.Email} after having updated the * email session from the property file. * * @param email * @return true if the email has been sent successfully, false otherwise. * @throws org.apache.commons.mail.EmailException * */ public static void sendCustomEmail(org.apache.commons.mail.Email email) throws EmailException { email.setMailSession(Session.getInstance(Utils.loadProperties(SMTP_FILE))); email.setDebug(true); email.send(); } }
public void send(Email email) throws EmailException{ boolean sendForReal = env.has(SEND_REAL_EMAIL) || env.getName().equals("production"); if (sendForReal) { logger.info("REAL MAIL ::: {} ::: {}", email.getSubject(), email.getToAddresses()); if (email.getFromAddress() == null) { email.setFrom(env.get(FROM)); } if (env.has(REPLY_TO)) { email.addReplyTo(env.get(REPLY_TO)); } email.setMailSession(session); try { client.sendRawEmail(new SendRawEmailRequest() .withRawMessage(mail2Content(email))); } catch (Exception e) { throw new EmailException(e); } } else { new MockMailer().send(email); } } }