At a recent client engagement, the client asked to review the Hybris Commerce Out-of-the-Box (OOTB) email templates' copy early in the project. During this engagement, I worked off-site on most days, and could not reliably access the client's SMTP Server to send emails from Hybris. In this situation, I decided to use my Gmail account to send Hybris emails to the client directly. In this tutorial, I will demonstrate how to send emails from Hybris Commerce using Google Mail (Gmail).
Prerequisites: To complete this tutorial, you will need a Google Mail (Gmail) account.
Note: Hybris Commerce 6.x OOTB has SMTP disabled in the project. properties file.
- Copy the commented SMTP configuration settings from the project.properties file, then paste these settings into the local.properties file in your preferred IDE. It's considered a best practice to make custom changes to the local.properties (located in the config directory) file instead of modifying the project.properties file. For good measure, I will also update the mail.from and mail.replyto properties. After pasting the SMTP settings into the local.properties file, the local.properties file should now include the following settings:
- Un-comment the SMTP Settings in the local.properties file. Remove the (#) symbols at the beginning of each SMTP configuration setting.
Your local.properties file should now resemble the following:
- Update the SMTP Settings with your Google Mail (Gmail) settings and set mail.use.tls to true . Insert your gmail.com address where you see firstname.lastname@example.org in the next screen capture. Note: Google Mail is the email provider for hybrisarchitect.com. Custom domain email addresses hosted with Google Mail are also supported. The following settings are required to send emails using Google Mail:
- Open the command prompt.
- Go to <HYBRIS_BIN_DIR>/platform , and start Hybris by running hybrisserver.bat (Windows) or ./hybrisserver.sh (Linux).
No need to perform an ant all command, it's not required for property file modifications. However, you will need to stop Hybris, if it is currently running, then restart by running the hybrisserver.bat or /hybrisserver.sh. After several minutes, Hybris should be up and running.
- Sign into HAC to verify the email settings are configured properly in Hybris.
- Once you've signed in successfully, click on Platform-> Configuration.
- Type SMTP into the Search Box to confirm the SMTP settings have been properly configured in Hybris. The mail.smtp.password, mail.smtp.port, mail.smtp.server and mail.smtp.user should contain the values set in the local.properties file in step #3.
- Type tls into the Search Box to confirm the mail.use.tls setting has been properly set to true.
- The tutorial is complete, now you know how to send e-mails from Hybris Commerce using Google Mail.
If you receive the following error: Script execution has failed [reason: org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:587]
1. Go to your Google Account's Less Secure Apps page: https://myaccount.google.com/lesssecureapps
2. Set Allow less secure apps to ON
Watch the Video