Skip to content

This project contains how to send Email, Email with HTML content, and Email with Attachment & HTML content using Spring boot.

Notifications You must be signed in to change notification settings

SATISH-SINGH95/Send-Email-With-Spring-Boot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Boot Email Service

Overview

This project demonstrates how to send emails using Spring Boot. It covers sending plain text emails, emails with HTML content, and emails with attachments. The application leverages Spring Boot's email integration features to simplify the process of sending various types of emails.

Features

  • Send plain text emails.
  • Send emails with HTML content.
  • Send emails with attachments and HTML content.

Prerequisites

  • Java 8 or higher
  • Maven 3.6.3 or higher
  • An email account (e.g., Gmail) for testing the email sending functionality

Getting Started

  • Clone the Repository
git clone https://github.com/SATISH-SINGH95/Send-Email-With-Spring-Boot cd spring-booot-email-service
  • Configure Email settings Update the application.properties file with your email server details. For example, if you are using Gmail, you can configure it as follows:
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=your-email@gmail.com
spring.mail.password=your-email-password
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true

Note: It is recommended to use application-specific passwords and not your actual email password for security reasons. Additionally, consider using environment variables or a secure vault for sensitive configurations.

Build and Run the application

mvn clean install
mvn spring-boot:run

Usage

Sending a Plain Text Email

To send a plain text email, make a POST request to /email/send-email with the following JSON payload:

{
    "to": "recipient@example.com",
    "subject": "Test Plain Email",
    "message": "This is a plain text email."
}

Sending an Email with HTML Content

To send an email with HTML content, make a POST request to /email/send-email-with-html with the following JSON payload:

{
    "to": "recipient@example.com",
    "subject": "Test HTML Email",
    "message": "<h1>This is an HTML email</h1><p>with some <b>bold</b> text.</p>"
}

Sending an Email with Attachment and HTML Content

To send an email with an attachment and HTML content, make a POST request to '/email/send-email-with-attachment' with the following form-data:

  • to: Recipient email address (e.g., 'recipient@example.com')
  • subject: Email subject (e.g., 'Test Email with Attachment')
  • message: Recipient email address (e.g., 'This message is in h1 tag')
  • file: File to be attached (select a file from your system)
{
    "to": "recipient@example.com",
    "subject": "Test HTML Email",
    "message": "<h1>This is an HTML email</h1><p>with some <b>bold</b> text.</p>"
}
  • API Endpoints:
    • `POST /email/send-email -> Send a plain text email
    • `POST /email/send-email-with-html -> Send an email with HTML content
    • `POST /email/send-email-with-attachment -> Send an email with an attachment and HTML

Dependencies

  • spring-boot-starter-mail
  • spring-boot-starter-web
  • spring-boot-devtools
  • lombok
  • spring-boot-starter-tomcat
  • spring-boot-starter-validatio
  • springdoc-openapi-starter-webmvc-ui

Contributing

Contributions are welcome! Please fork the repository and create a pull request with your changes.

Contact

For questions or feedback, please contact sk95satish@gmail.com

About

This project contains how to send Email, Email with HTML content, and Email with Attachment & HTML content using Spring boot.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages