LoginSignup
3
1

More than 3 years have passed since last update.

spring bootでメール送信

Posted at

メモ

pom.xml
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-mail</artifactId>
</dependency>
application.yml

spring:
  mail:
    host: smtp.●●.●●(gmailなら「smtp.gmail.com」)
    port: 587
    username: (メールアドレス)
    password: (パスワード)
    properties.mail.smtp.auth: true
    properties.mail.smtp.starttls.enable: true
sample

@Autowired
    private MailSender sender;

    public void sendMail() {
        SimpleMailMessage msg = new SimpleMailMessage();

        msg.setFrom("送信元メールアドレス");
        msg.setTo("送信先メールアドレス");
        msg.setSubject("件名入力欄");
        msg.setText("本文入力欄");

        this.sender.send(msg);
    }

sampleはクラス内に書くこと。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1