SendMailFactory (Apache Tomcat 11.0.24 API Documentation)
Description: declaration: package: org.apache.naming.factory, class: SendMailFactory

# Class SendMailFactory

java.lang.Object
org.apache.naming.factory.SendMailFactory

All Implemented Interfaces:
  `ObjectFactory`

public class SendMailFactory extends Object implements ObjectFactory
Factory class that creates a JNDI named javamail MimePartDataSource object which can be used for sending email using SMTP.

Can be configured in the Context scope of your server.xml configuration file.

Example:

    <Resource name="mail/send"
              auth="CONTAINER"
              type="jakarta.mail.internet.MimePartDataSource"
              factory="org.apache.naming.factory.SendMailFactory"
              mail.smtp.host="your.smtp.host"
              mail.smtp.user="someuser"
              mail.from="someuser@some.host"
              mail.smtp.sendpartial="true"
              mail.smtp.dsn.notify="FAILURE"
              mail.smtp.dsn.ret="FULL"
              />

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected static final String`
  `DataSourceClassName`
  The class name for the javamail MimePartDataSource.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SendMailFactory()`
  Default constructor.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Object`
  `getObjectInstance(Object refObj, Name name, Context ctx, Hashtable<?,?> env)`
  Create a MimePartDataSource instance from the given JNDI reference.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### DataSourceClassName

    protected static final String DataSourceClassName
    The class name for the javamail MimePartDataSource.
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### SendMailFactory

    public SendMailFactory()
    Default constructor.

- ## Method Details

  - ### getObjectInstance

    public Object getObjectInstance(Object refObj, Name name, Context ctx, Hashtable<?,?> env) throws Exception
    Create a MimePartDataSource instance from the given JNDI reference.
    Specified by:
      `getObjectInstance` in interface `ObjectFactory`
    Parameters:
      `refObj` - the JNDI reference object
      `name` - the JNDI name
      `ctx` - the JNDI context
      `env` - the environment properties
    Returns:
      a MimePartDataSource instance, or null if the reference class does not match
    Throws:
      `Exception` - if an error occurs during creation