Search in sources :

Example 1 with MailSessionAuthenticator

use of org.glassfish.resources.javamail.MailSessionAuthenticator in project Payara by payara.

the class MailNamingObjectFactory method getObjectInstance.

public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
    Reference ref = (Reference) obj;
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "MailNamingObjectFactory: " + ref + " Name:" + name);
    }
    MailConfiguration config = (MailConfiguration) ref.get(0).getContent();
    // Note: javax.mail.Session is not serializable,
    // but we need to get a new instance on every lookup.
    Properties props = config.getMailProperties();
    javax.mail.Session s = javax.mail.Session.getInstance(props, new MailSessionAuthenticator(props));
    if ("smtps".equals(props.getProperty("mail.transport.protocol"))) {
        s.setProtocolForAddress("rfc822", "smtps");
    }
    s.setDebugOut(new PrintStream(new MailLogOutputStream()));
    s.setDebug(true);
    return s;
}
Also used : MailConfiguration(com.sun.enterprise.deployment.MailConfiguration) PrintStream(java.io.PrintStream) Reference(javax.naming.Reference) MailLogOutputStream(org.glassfish.resources.javamail.MailLogOutputStream) MailSessionAuthenticator(org.glassfish.resources.javamail.MailSessionAuthenticator) Properties(java.util.Properties)

Aggregations

MailConfiguration (com.sun.enterprise.deployment.MailConfiguration)1 PrintStream (java.io.PrintStream)1 Properties (java.util.Properties)1 Reference (javax.naming.Reference)1 MailLogOutputStream (org.glassfish.resources.javamail.MailLogOutputStream)1 MailSessionAuthenticator (org.glassfish.resources.javamail.MailSessionAuthenticator)1