Configuring Email with - Gmail and more… Permalink to "Configuring Email with - Gmail and more…"
Tip submitted by @RawSanj
Goal: By the using below mail settings you will have the default JHipster application configured to send emails from Gmail, Outlook or Yahoo.
Start by running JHipster with jhipster
to create a new application or use an existing JHipster generated application.
Configure ‘from’ address Permalink to "Configure ‘from’ address"
Open src\main\resources\config\application.yml
, edit jhipster.mail.from
property:
application.yml
jhipster:
[...]
mail:
from: username@service_provider #Replace this field with the value that will be used for spring.mail.username
[...]
Skipping this step will likely to result in your email is marked as spam.
Choose any of below Email Service for your Application : Permalink to "Choose any of below Email Service for your Application :"
1. Email Config - Gmail Permalink to "1. Email Config - Gmail"
Go into src\main\resources\config\application-dev.yml
and change your application to use the below Gmail configuration:
application-dev.yml
spring:
profiles:
active: dev
mail:
host: smtp.gmail.com
port: 587
username: [email protected] #Replace this field with your Gmail username.
password: ************ #Replace this field with your Gmail password/App password.
protocol: smtp
tls: true
properties.mail.smtp:
auth: true
starttls.enable: true
ssl.trust: smtp.gmail.com
[...]
If you use the above configuration with your Gmail password, you might need to allow less secure apps. The configuration is simpler but less secure. Also by allowing less secure apps you won’t have the ability to use two factor authentication with Gmail.
Therefore we highly recommend you use an app password instead of the Gmail password. Please refer to the following Gmail configuration document for more information on how to set this up.
https://support.google.com/accounts/answer/185833
This way you will be able to use two factor authentication as well as keep the “allow less secure apps” option off. You can also use OAuth2 with Gmail and the configuration method is highlighted in the following document.
https://javaee.github.io/javamail/OAuth2
2. Email Config - Outlook.com Permalink to "2. Email Config - Outlook.com"
Go into src\main\resources\config\application-dev.yml
and change your application to use the below Outlook configuration:
application-dev.yml
spring:
profiles:
active: dev
mail:
host: smtp-mail.outlook.com
port: 587
username: [email protected] #Replace this field with your Outlook username.
password: ************ #Replace this field with your Outlook password.
protocol: smtp
tls: true
properties.mail.smtp:
auth: true
starttls.enable: true
ssl.trust: smtp-mail.outlook.com
[...] __Note__ : If you want to send Email from a Corporate Outlook account then set `host` as the Microsoft Exchange Server of your company, for e.g. `emea.mycompany.com`. Also set `username` as Standard Id of the system provided by the company (Domain/Username) and `password` as your system password. For Corporate Outlook, `username` property in **spring.mail** must match the `from` property in **jhipster.mail**.
Tip : To find your Microsoft Exchange Server
: Open Outlook > Click Tools > Click Account Settings… > Double Click on Microsoft Exchange (under Email tab) and copy the Microsoft Exchange Server address.
3. Email Config - Yahoo Permalink to "3. Email Config - Yahoo"
Go into src\main\resources\config\application-dev.yml
and change your application to use the below Yahoo configuration:
application-dev.yml
spring:
profiles:
active: dev
mail:
host: smtp.mail.yahoo.com
port: 587
username: [email protected] #Replace this field with your Yahoo username.
password: ************ #Replace this field with your Yahoo password.
protocol: smtp
tls: true
properties.mail.smtp:
auth: true
starttls.enable: true
ssl.trust: smtp.mail.yahoo.com
[...]
jhipster:
mail:
from: [email protected] #Replace this field with your Gmail username.
[...] __Note__ : For Yahoo Mail, `username` property in **spring.mail** must match the `from` property in **jhipster.mail**.
4. Email Config - Zoho Permalink to "4. Email Config - Zoho"
Go into src\main\resources\config\application-dev.yml
and change your application to use the below Zoho configuration:
application-dev.yml
spring:
profiles:
active: dev
mail:
host: smtp.zoho.com
port: 587
username: [email protected] #Replace this field with your Zoho username.
password: ************ #Replace this field with your Zoho password.
protocol: smtp
tls: true
properties.mail.smtp:
auth: true
starttls.enable: true
ssl.trust: smtp.zoho.com
[...]
4. Email Config - AWS SES Permalink to "4. Email Config - AWS SES"
Go into src\main\resources\config\application-dev.yml
and change your application to use the below AWS SES configuration:
application-dev.yml
spring:
profiles:
active: dev
mail:
host: email-smtp.us-east-1.amazonaws.com
port: 465
username: ********************
password: ********************************************
protocol: smtps
debug: true
properties.mail.smtp:
starttls.enable: true
starttls.required: true
ssl.enable: true
properties.mail.smtps:
auth: true
Similarly you can configure any other email service. Just check the SMTP Mail Server and Server Port of your Email Service and change the above fields accordingly
Now run your application! Go to Register Page, submit the form with a valid Email addrees and you should receive an Activation Email from the above configured Email Address.
Note : You can try sending test Emails with your credentials using these examples.