Skip to content

Instantly share code, notes, and snippets.

@mmafrar
Created April 29, 2021 19:08
Show Gist options
  • Save mmafrar/4c7bb94f418bd64b92d05c67400687b4 to your computer and use it in GitHub Desktop.
Save mmafrar/4c7bb94f418bd64b92d05c67400687b4 to your computer and use it in GitHub Desktop.
Sending emails in Spring Boot with Amazon SES SMTP Interface
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