---
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://sendcorex.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://sendcorex.com/llms.txt"
---

Source: https://sendcorex.com/ja/blog/spring-boot-send-email-smtp

チュートリアル

# Spring Boot（JavaMailSender）でSMTP経由でメールを送る

spring-boot-starter-mail、5つのプロパティ、小さなサービスクラス。プレーンテキストとHTML。

Sendcorexチーム·更新日 2026年11月18日·6分で読めます

## 1. mail starterを追加する

```
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-mail</artifactId>
</dependency>
```

## 2. application.propertiesでSMTPを設定する

```
spring.mail.host=smtp.sendcorex.com
spring.mail.port=587
spring.mail.username=${SENDCOREX_API_KEY}
spring.mail.password=${SENDCOREX_API_KEY}
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
```

キーはリポジトリではなく、必ず環境変数に置きましょう。

## 3. プレーンテキストのメールを送る

```
@Service
public class MailService {
  private final JavaMailSender mailer;

  public MailService(JavaMailSender mailer) { this.mailer = mailer; }

  public void sendWelcome(String to) {
    SimpleMailMessage msg = new SimpleMailMessage();
    msg.setFrom("Acme <hello@yourdomain.com>");
    msg.setTo(to);
    msg.setSubject("Welcome to Acme");
    msg.setText("Thanks for signing up!");
    mailer.send(msg);
  }
}
```

## 4. HTMLを送る

```
MimeMessage mime = mailer.createMimeMessage();
MimeMessageHelper h = new MimeMessageHelper(mime, true, "UTF-8");
h.setFrom("hello@yourdomain.com", "Acme");
h.setTo(to);
h.setSubject("Your receipt");
h.setText("Your receipt is attached.", "<html><body><p>Your receipt is attached.</p></body></html>");
mailer.send(mime);
```

プレーンテキスト版とHTML版の両方を渡し、HTMLは`<html>`と`<body>`タグのある完全なドキュメントとして送りましょう。断片だけのHTMLはよくあるスパムのシグナルです。

## 5. ドメインを認証する

本番公開の前に、Sendcorexにドメインを追加し、表示されるSPF、DKIM、DMARCレコードを公開してください。すべてのメールで、ブランドと一致する同じ送信者名を使いましょう。 [SPFジェネレーター](https://sendcorex.com/ja/tools/spf-generator) と [DMARCジェネレーター](https://sendcorex.com/ja/tools/dmarc-generator) でレコードを作成できます。

## よくある質問

### Spring BootのSMTPにはどのポートを使うべきですか？

STARTTLS（mail.smtp.starttls.enable=true）で587番ポートを使います。ネットワークで587がブロックされている場合だけ、mail.smtp.ssl.enable=trueで465を使ってください。

### JavaMailSenderがタイムアウトするのはなぜですか？

通常、ホスティング事業者が送信用のSMTPポートをブロックしています。2525か465を試すか、代わりにHTTPSでREST Email APIを呼び出してください。

### このページの内容

数分でSpring Bootから送信

無料アカウントを作成し、ドメインを認証して、上のプロパティを貼り付けましょう。

[無料で始める — 月3,000通](https://app.sendcorex.com/authentication/register?appid=smtp)

クレジットカード不要

## 続きを読む

[チュートリアル ### .NET（C#）でSMTP経由でメールを送る SMTP経由でSystem.Net.MailかMailKitを使います。HTMLメール、添付ファイル、エラー処理、DNS設定付き。 ガイドを読む](https://sendcorex.com/ja/blog/send-email-dotnet) [到達率 ### SPF、DKIM、DMARCの解説 メールと受信箱の間には3つのDNSレコードがあります。それぞれが実際に何を証明するのか、1つ欠けると何が起こるのかを解説します。 ガイドを読む](https://sendcorex.com/ja/blog/spf-dkim-dmarc-explained) [到達率 ### メール到達率チェックリスト：送信前の16項目 最初の本番送信の前に確認すべきことのすべて。初日からメールボックスプロバイダーに不信感を抱かせず、受信箱に届けるために。 ガイドを読む](https://sendcorex.com/ja/blog/email-deliverability-checklist)

数分でSpring Bootから送信

無料アカウントを作成し、ドメインを認証して、上のプロパティを貼り付けましょう。

クレジットカード不要

[無料で始める — 月3,000通](https://app.sendcorex.com/authentication/register?appid=smtp) [料金を見る](https://sendcorex.com/ja/pricing)
