Java mail usage for different providers | scenarios with Jakarta
- Testing local with MailHog | Fake SMTP Server
Prerequisites:
- use docker for MailHog see - docs
docker run -p 8025:8025 -p 1025:1025 -d mailhog/mailhogor docker compose
services: mailhog: image: mailhog/mailhog logging: driver: 'none' # disable saving logs ports: - 1025:1025 # smtp server - 8025:8025 # web ui-
check the emails on http://localhost:8025
-
for Fake SMTP Server you can download the .jar file from site
- Testing with Gmail SMTP Server (no Oauth2, just user and app password)
You will need an app password from your Google Account (can be generated only if 2FA is active). see docs TLS or SSL can be used see docs
Extra guides here
- Testing with Microsoft 365
For this you need to configure some stuff. Follow the official guide and configure the app in MS365 for client credential flow. Don't forget to do this. Turn on IMAP / POP3 if needed (Gmail / Settings / Forwarding and POP/IMAP)
You will need an access token from the token endpoint for your app based on:
- a client secret
- the client id (the app id)
- the scope
https://outlook.office365.com/.default - grant_type:
client_credentials
Use the token as a password in code.