7 minutes
8 Key Benefits of Application Modernization for Business Growth
Modernizing enterprise applications is a strategic imperative for organizations that want to remain competitive and resilient. According to our […]

Thanks Alessio, is it possible to use this to send emails from an application?
Hi Martin,
The Notification service is used to route events from the Payara container not from applications. The email notifier uses a standard JavaEE JavaMail session, which can also be used from an application to send emails.
Here’s an example of such an application: https://github.com/javaee-samples/javaee7-samples/blob/master/javamail/definition/src/main/java/org/javaee7/javamail/definition/AnnotatedEmailServlet.java
To use the JavaMail session configuration described in the blog, just use its JNDI name in @Resource when you inject javax.mail.Session. If you do so, you don’t need to define a JavaMail resource in the application using @MailSessionDefinition.
Hi, please help,
How it must be configured for payra micro?
Hi,
You can configure JavaMail session definition and also Notification Service and the JavaMail notifier in Payara Micro with asadmin commands (the same which work with Payara Server) in a file using the –postbootcommandfile argument (documentation here: https://docs.payara.fish/documentation/payara-micro/asadmin/pre-and-post-boot-scripts.html)
You need to configure the JavaMail session with these asadmin commands:
create-javamail-resource
create-resource-ref
set resources.mail-resource.mail/myMailSession.property.mail.smtp.* (instead of * you need to pass each property separately).
For example, this would configure the same JavaMail session as in the article above (note that dots after property. have to be escaped with ):
create-javamail-resource –debug=false –storeProtocol=imap –auth=false –transportProtocol=smtp –host=smtp.gmail.com –storeProtocolClass=com.sun.mail.imap.IMAPStore –from=default-sender@email.com –transportProtocolClass=com.sun.mail.smtp.SMTPTransport –user=default@email.com –enabled=true –target=domain mail/myMailSession
create-resource-ref –enabled=true –target=server mail/myMailSession
set resources.mail-resource.mail/myMailSession.property.mail.smtp.user=myemail@gmail.com resources.mail-resource.mail/myMailSession.property.mail.smtp.password=${ALIAS=mygmail_pwd} resources.mail-resource.mail/myMailSession.property.mail.smtp.auth=true resources.mail-resource.mail/myMailSession.property.mail.smtp.port=465 resources.mail-resource.mail/myMailSession.property.mail.smtp.socketFactory.port=465 resources.mail-resource.mail/myMailSession.property.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
Hi,
please help! How it must be configured for payara micro?
How can we do it with Docker? Is it possible?
Hi Stanyslas,
Everything is possible in Docker but the best practice is to configure everything using asadmin commands in the Dockerfile. You can execute asadmin commands either during build time (during the build, you need to start the server, execute the commands and then stop the server). You can execute the same commands also upon server startup each time the container is started, with the –prebootcommandfile argument (https://docs.payara.fish/documentation/payara-server/app-deployment/app-deployment.html), which you can add to the end of the docker run command.
An example of asadmin commands that configure a JavaMail session as in the article above (dots after “properties.” have to be escaped with ):
create-javamail-resource –debug=false –storeProtocol=imap –auth=false –transportProtocol=smtp –host=smtp.gmail.com –storeProtocolClass=com.sun.mail.imap.IMAPStore –from=default-sender@email.com –transportProtocolClass=com.sun.mail.smtp.SMTPTransport –user=default@email.com –enabled=true –target=domain mail/myMailSession
create-resource-ref –enabled=true –target=server mail/myMailSession
set resources.mail-resource.mail/myMailSession.property.mail.smtp.user=myemail@gmail.com resources.mail-resource.mail/myMailSession.property.mail.smtp.password=${ALIAS=mygmail_pwd} resources.mail-resource.mail/myMailSession.property.mail.smtp.auth=true resources.mail-resource.mail/myMailSession.property.mail.smtp.port=465 resources.mail-resource.mail/myMailSession.property.mail.smtp.socketFactory.port=465 resources.mail-resource.mail/myMailSession.property.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
You also need to configure the Notification service and the JavaMail notifier with another set of asadmin commands.
many thanks, I did it the same way you presented it and it is working, I want to move to Docker and I will apply the same approach as describe before, many thanks for the support. One important point is also to open appropriate Port also and if there is firewall to configure outbound communication also.
I saw also that there is possibility to do clustering with Payara Micro and Docker, please tell me if we need to configure it on all servers or just one….