
Leading the Way: Payara Platform Community 7 Beta Now Fully Jakarta EE 11 Certified
We’re excited to announce that Payara Platform Community 7 Beta application server is now fully certified as Jakarta EE 11 […]
The latest version of Payara Server extends the Notification Service with many ways how to process notifications and send them to external services. Sending notifications as email messages to an SMTP server is now provided out of the box. It is even possible to use an account on a public email server, such as Gmail. In this guest blog, Alessio Gennari – a member of the Payara open source community – explains to you exactly how it can be done.
{{cta(‘397f0696-0d00-4949-b21a-72e4dfbd321d’)}}
To successfully configure a JavaMail Session in Payara Server 171 with your Gmail account, first you need to modify the following settings for a JavaMail session in Payara Server:
Now you need to set some additional properties of the JavaMail Session to enable Payara Server to send emails through your Gmail account. Here are the properties you have to set:
You can find the correct settings in the following figure:
All other settings can be left at default values.
Now you can enable email notifications using the JNDI name of the JavaMail session, and Payara Server can send notifications via your Gmail account.
{{cta(‘f53ec10a-12d5-483b-b089-2d4cdab10448’)}}
Share:
We’re excited to announce that Payara Platform Community 7 Beta application server is now fully certified as Jakarta EE 11 […]
Enterprise Java applications power global commerce, healthcare, government and countless other industries. These systems must be scalable, secure and […]
May 2025 marks a monumental milestone in software development: Java turns 30. The impact of this language on the […]
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….