How to set up a Mail Server with DXP to receive email notifications?

Issue

  • This article outlines how to set up a Mail Server and SMTP in Liferay DXP to receive emails.

Environment

  • Liferay DXP 7.3

Resolution

  • Liferay DXP uses a mail server and SMTP to get email notifications. Liferay DXP’s built-in mail session is the easiest way to configure mail and it’s recommended.
  • To fully utilize this, users need to go through some steps on Google's end. To receive emails, users must enable 'Less Secure Apps' settings, however, Google stopped supporting less secure apps on May 30th, 2022. As a result, instead of this step, use 2-Step Verification and generate an app password.
    • Google Account > Security > 2-Step Verification > Input password as asked > Turn ON
    • Google Account > Security > App password > Input password as asked > Select the app >  Custom name -> Input app name (e.g. Myemails )-> Generateprotect-your-security-ss.pngApp-Password-SS.png
    • Copy a 16-character password
    • Use a 16-character password with a Gmail username (xxx@gmail.com) on the Liferay side.
  • Set up IMAP and change your SMTP settings to read Gmail messages
    • On your computer, open Gmail.
    • In the top right, click Settings Settings and then See all settings.
    • Click the Forwarding and POP/IMAP tab.
    • In the 'IMAP Access' section, select Enable IMAP.
    • Click Save Changes.
  • Now, configuring Liferay DXP’s Built-in Mail Session in the Control Panel.
    • Navigate to Control Panel-> System-> Server Administration-> Mail
    • Outgoing SMTP Server: Liferay DXP uses this server to send emails, such as password change emails and other notifications (as the Gmail server has been used here, and the Gmail SMTP server address is smtp.gmail.com
      Outgoing Port: The port on which the SMTP server is listening (SMTP Ports 25, 465, & 587. The 465 port has been used here)
      Use a Secure Network Connection: Check this option.
      User Name: The user ID Liferay DXP should use to log into the SMTP server.
      Password: Use the generated 16-character password generated by the Gmail side.

OutgoingPort-details.png

    • Click on the Save button
    • Navigate to Control Panel-> Instance Settings-> Email-> Email Sender, change Name and Address.Emial-Sender.png

Additional Information

  • Google Support Link: Sign in using app passwords
  • By creating a new user and changing their password, the configuration can be validated.
  • To avoid the issues shown below, double-check the login and password or check the 2-Step Verification step
ERROR [liferay/mail-4][MailEngine:74] Unable to send message: 535-5.7.8 Username and Password not accepted. Learn more at_535 5.7.8 https://support.google.com/mail/?p=BadCredentials y12sm2192864pgk.7 - gsmtp_ [Sanitized]
javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. Learn more at_535 5.7.8 https://support.google.com/mail/?p=BadCredentials y12sm2192864pgk.7 - gsmtp_ [Sanitized]
at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:965)
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:876)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:780)
at javax.mail.Service.connect(Service.java:388)
at com.liferay.petra.mail.MailEngine._send(MailEngine.java:587)
at com.liferay.petra.mail.MailEngine.send(MailEngine.java:387)
at com.liferay.petra.mail.MailEngine.send(MailEngine.java:462)
at com.liferay.mail.messaging.MailMessageListener.doMailMessage(MailMessageListener.java:99)
at com.liferay.mail.messaging.MailMessageListener.doReceive(MailMessageListener.java:114)
at com.liferay.portal.kernel.messaging.BaseMessageListener.doReceive(BaseMessageListener.java:48)
Was this article helpful?
1 out of 3 found this helpful