Created
April 29, 2021 19:08
-
-
Save mmafrar/4c7bb94f418bd64b92d05c67400687b4 to your computer and use it in GitHub Desktop.
Sending emails in Spring Boot with Amazon SES SMTP Interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.demo; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.web.bind.annotation.GetMapping; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
import org.springframework.web.bind.annotation.RestController; | |
import javax.mail.MessagingException; | |
import java.io.UnsupportedEncodingException; | |
@RestController | |
@RequestMapping("api/v1") | |
public class DefaultController { | |
@Autowired | |
private EmailService emailService; | |
@GetMapping("/index") | |
public void index() { | |
String recipient = "<YOUR_EMAIL_ADDRESS>"; | |
String subject = "Amazon SES SMTP Interface"; | |
String content = "<p>Hi there, this is a test email.</p>"; | |
try { | |
emailService.sendEmail(recipient, subject, content); | |
} catch (UnsupportedEncodingException | MessagingException e) { | |
System.out.println(e.getStackTrace()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment