Search in sources :

Example 1 with MailConfiguration

use of com.sun.enterprise.deployment.MailConfiguration in project Payara by payara.

the class MailResourceDeployer method installMailResource.

/**
 * Installs the given mail resource. This method gets called during server
 * initialization and from mail resource deployer to handle resource events.
 *
 * @param mailResource mail resource
 * @param resourceInfo
 */
public void installMailResource(MailBean mailResource, ResourceInfo resourceInfo) {
    try {
        MailConfiguration config = new MailConfiguration(mailResource);
        javax.naming.Reference ref = new javax.naming.Reference(javax.mail.Session.class.getName(), MailNamingObjectFactory.class.getName(), null);
        SerializableObjectRefAddr serializableRefAddr = new SerializableObjectRefAddr("jndiName", config);
        ref.add(serializableRefAddr);
        // Publish the object
        namingService.publishObject(resourceInfo, ref, true);
    } catch (Exception ex) {
        _logger.log(Level.SEVERE, "mailrsrc.create_obj_error", resourceInfo);
        _logger.log(Level.SEVERE, "mailrsrc.create_obj_error_excp", ex);
    }
}
Also used : MailConfiguration(com.sun.enterprise.deployment.MailConfiguration) MailNamingObjectFactory(org.glassfish.resources.javamail.naming.MailNamingObjectFactory) SerializableObjectRefAddr(org.glassfish.resources.naming.SerializableObjectRefAddr) NamingException(javax.naming.NamingException) ResourceConflictException(org.glassfish.resourcebase.resources.api.ResourceConflictException)

Example 2 with MailConfiguration

use of com.sun.enterprise.deployment.MailConfiguration 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)2 PrintStream (java.io.PrintStream)1 Properties (java.util.Properties)1 NamingException (javax.naming.NamingException)1 Reference (javax.naming.Reference)1 ResourceConflictException (org.glassfish.resourcebase.resources.api.ResourceConflictException)1 MailLogOutputStream (org.glassfish.resources.javamail.MailLogOutputStream)1 MailSessionAuthenticator (org.glassfish.resources.javamail.MailSessionAuthenticator)1 MailNamingObjectFactory (org.glassfish.resources.javamail.naming.MailNamingObjectFactory)1 SerializableObjectRefAddr (org.glassfish.resources.naming.SerializableObjectRefAddr)1