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.
- Send plain text emails.
- Send emails with HTML content.
- Send emails with attachments and HTML content.
- Java 8 or higher
- Maven 3.6.3 or higher
- An email account (e.g., Gmail) for testing the email sending functionality
- 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.
mvn clean install
mvn spring-boot:run
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."
}
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>"
}
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
- 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
Contributions are welcome! Please fork the repository and create a pull request with your changes.
For questions or feedback, please contact sk95satish@gmail.com