MailHandler , included in JavaMail 1.5.3 and later built in support for Google App Engine . Make sure you are using the latest version of JavaMail.
For GAE / J, you can download logging-mailhandler.jar and include it in your project.
<dependency> <groupId>com.sun.mail</groupId> <artifactId>logging-mailhandler</artifactId> <version>1.5.3</version> <scope>system</scope> <systemPath>FILE_PATH_TO/logging-mailhandler.jar</systemPath> </dependency>
Otherwise, you can use the java.net Maven or Maven Central repository and pull the dependency using groupid = com.sun.mail and artifactId = logging-mailhandler.
<dependency> <groupId>com.sun.mail</groupId> <artifactId>logging-mailhandler</artifactId> <version>1.5.3</version> </dependency>
After the dependency setting is configured, configure the logging settings so that they contain the correct logging and email envlope settings. Here is an example logging.properties file:
Next, create code to install MailHandler , because LogManager won. Unable to see logging-mailhandler.jar .
Here is an example ServletContextListener that will install MailHandler in the root log.
import com.sun.mail.util.logging.*; import static com.google.appengine.api.ThreadManager.backgroundThreadFactory; import java.util.Arrays; import static java.util.concurrent.Executors.newScheduledThreadPool; import java.util.concurrent.Future; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.logging.Formatter; import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.Logger; import java.util.logging.MemoryHandler; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; public class MailHandlerConfig implements ServletContextListener, Runnable { private static final String LOGGER_NAME = ""; private static final Logger logger = Logger.getLogger(LOGGER_NAME); private volatile ScheduledExecutorService ses; private volatile Future<?> task; private volatile Handler handler; @Override public void contextInitialized(ServletContextEvent sce) { MailHandler mh = new MailHandler(); mh.setSubject(defaultSubject()); handler = mh; try { handler = new MemoryHandler(mh, mh.getCapacity(), mh.getPushLevel()); ses = newScheduledThreadPool(1, backgroundThreadFactory()); task = ses.scheduleAtFixedRate(this, 30L, 30L, TimeUnit.MINUTES); } catch (RuntimeException | LinkageError re) { logger.log(Level.WARNING, "Unable to create push thread.", re); Level lvl = mh.getLevel(); if (lvl.intValue() < mh.getPushLevel().intValue()) { mh.setPushLevel(lvl); handler = mh; logger.log(Level.WARNING, "Forcing push level to {0}.", lvl); } } logger.addHandler(handler); logger.log(Level.INFO, "Application initialized. {0}", Arrays.toString(logger.getHandlers())); } @Override public void contextDestroyed(ServletContextEvent sce) {