Java Email Application
Using JavaMail API to send emails using SMTP from Java applications:
- without authentication,
- with TLS Authentication,
- with SSL Authentication and Email attachment and image.
- Java 9
- JavaMail API
- Gmail SMTP server
i. Clone the git repo
https://github.com/AAdewunmi/Java-Email-Application.git
ii. Open project folder
iii. Explore
😎
To send emails:
- without authentication -> Run in IDE ->
src/main/java/com/application/SimpleEmail.java
, - with TLS Authentication -> Run in IDE ->
src/main/java/com/application/TLSEmail.java
, - with SSL Authentication and Email attachment and image Run in IDE ->
src/main/java/com/application/SSLEmail.java
.
java.net.UnknownHostException
comes when your system is not able to resolve the IP address for the SMTP server, it might be wrong or not accessible from your network. For example, GMail SMTP server issmtp.gmail.com
and if I usesmtp.google.com
, I will get this exception. If the hostname is correct, try to ping the server through command line to make sure it’s accessible from your system.
- If your program is stuck in Transport send() method call, check that SMTP port is correct. If it’s correct then use telnet to verify that it’s accessible from you machine, you will get output like below.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Author: Pankaj (Developer and author at DigitalOcean)
Tutorial Title: JavaMail Example - Send Mail in Java using SMTP
Tutorial URL: https://www.digitalocean.com/community/tutorials/javamail-example-send-mail-in-java-smtp
Date: August 3, 2022