-
-
Save eksahin/262cfc3b346b51890b574a5544096360 to your computer and use it in GitHub Desktop.
send mail to AWS SES using spring boot
This file contains hidden or 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 org.test.demo; | |
import com.amazonaws.regions.Region; | |
import com.amazonaws.regions.Regions; | |
import com.amazonaws.services.simpleemail.AmazonSimpleEmailService; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.context.annotation.Configuration; | |
@Configuration | |
public class AppConfig { | |
@Autowired | |
AmazonSimpleEmailService amazonSimpleEmailService(AmazonSimpleEmailService amazonSimpleEmailService) { | |
// if use ses region change, write below. | |
amazonSimpleEmailService.setRegion(Region.getRegion(Regions.US_EAST_1)); | |
return amazonSimpleEmailService; | |
} | |
} |
This file contains hidden or 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
cloud.aws.credentials.accessKey=# write accessKey | |
cloud.aws.credentials.secretKey=# write secretKey |
This file contains hidden or 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 org.test.demo.service; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.mail.MailSender; | |
import org.springframework.mail.SimpleMailMessage; | |
import org.springframework.stereotype.Service; | |
@Service | |
public class MailSenderService { | |
private final MailSender mailSender; | |
@Autowired | |
public MailSenderService(MailSender mailSender) { | |
this.mailSender = mailSender; | |
} | |
public void sendMessage() { | |
SimpleMailMessage simpleMailMessage = new SimpleMailMessage(); | |
simpleMailMessage.setFrom("from@mailaddress"); | |
simpleMailMessage.setTo("to@mailaddress"); | |
simpleMailMessage.setSubject("subject"); | |
simpleMailMessage.setText("text"); | |
this.mailSender.send(simpleMailMessage); | |
} | |
} |
This file contains hidden or 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
<!-- add --> | |
<dependency> | |
<groupId>org.springframework.cloud</groupId> | |
<artifactId>spring-cloud-starter-aws</artifactId> | |
</dependency> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment