How to send email using springboot(the content of email using html and include image)

Published: 01 November 2023
on channel: Programming Tutorial
380
like

#sendeamil #mailserver #gmail #gmailsmtp #gmailspringboot
You can fork this tutorial from my github (https://github.com/AminTurmudiYusup/s...)
How to send email using springboot(the content of email using html and include image)
Prerequisite
1. Understand the concept mail server
2. Understand how to create spring boot app from scratch
3. your google account already do 2-Step verification and create APP-PAssword(if not, see my previous tutorial    • 2 Step verification and Create App Pa...  )
4. understand to mapping object with thymeleaf template




In this tutorial i will use this scenario
1. user hit entry point url and show registration page
2. input username, input email, input password and submit
3. redirect to success register page
4. send notification using email, if registration success
5. check email if notification is send


Let's Jump right in
1. this is my project structure
2. add dependency needed
3. configure thymeleaf template in application properties
4. configure mail server in application.properties
define mail host
define port(if you want using tls define 587 and if you want using ssl define using 465)
define you user name aka email
define your password, which created using App-Password in google
define smtp.auth ( SMTP authentication is a mechanism that allows you to log in to your SMTP server using a username and password before sending emails.)
define starttls.enable(STARTTLS (Transport Layer Security) for secure communication when sending emails using the SMTP protocol.)
5. create domain class inside model package(to bring data from front end to backend)
6. create template registration to send email using html
dont forget to include Thymeleaf XML namespace in html tag(xmlns:th="http://www.thymeleaf.org")
load bootstrap css and js( using content delivery network)
mapping domain class with input text registration template
7. Create class controller(to handle registration request)
8. create html template which include the image for sending email using html template
9. save image which want to include inside template, put in this path(/resources/static/images)
10. Create class service
create method to handle send email
create method to read images and encode using base code64
11. Create method to handle form action and send email
12. Create success_registration template, when registration already succed
13. Run the application

Hit entry point url(http://localhost:8080/registration/form)
check notification inside mail client

SUccess, You can download this code from my github.
Happy learning and happy sharing!!!


Watch video How to send email using springboot(the content of email using html and include image) online without registration, duration hours minute second in high quality. This video was added by user Programming Tutorial 01 November 2023, don't forget to share it with your friends and acquaintances, it has been viewed on our site 380 once and liked it like people.