---
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/send-email-nextjs

チュートリアル

# Next.jsからメールを送る（App RouterとRoute Handler）

App Routerのやり方：Server ActionからREST APIを直接呼び出します。SMTPクライアントは不要です。

Sendcorexチーム·更新日 2026年9月21日·8分で読めます

## ここでSMTPではなくRESTを使う理由

Next.jsのデプロイの多くはサーバーレスやエッジの関数で動いており、長時間の送信SMTP接続は不安定か、完全にブロックされています。Server ActionからHTTPSのPOSTを1回送れば、この問題を完全に回避できます。

## お問い合わせフォーム用のServer Action

```
// app/actions.ts
'use server';

export async function sendContactMessage(formData: FormData) {
  const email = formData.get('email') as string;
  const message = formData.get('message') as string;

  const res = await fetch('https://graph.sendcorex.com/v3.0/emails', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.SENDCOREX_API_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      to: 'you@yourdomain.com',
      from: 'hello@yourdomain.com',
      replyTo: email,
      subject: 'New contact message',
      text: message,
    }),
  });

  if (!res.ok) throw new Error('Could not send message');
}
```

## クライアントから呼び出したいならRoute Handlerでも

```
// app/api/contact/route.ts
export async function POST(request: Request) {
  const { email, message } = await request.json();

  const res = await fetch('https://graph.sendcorex.com/v3.0/emails', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.SENDCOREX_API_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ to: 'you@yourdomain.com', from: 'hello@yourdomain.com', replyTo: email, subject: 'New contact message', text: message }),
  });

  return Response.json({ ok: res.ok }, { status: res.ok ? 200 : 502 });
}
```

## React Emailでレンダリング

単純な文字列より凝ったものは、`@react-email/render`でReact EmailコンポーネントをHTMLにレンダリングし、結果をリクエストbodyの`html`として渡します。テンプレートを文字列連結ではなくコンポーネントとして管理できます。

## チェックリスト

- `SENDCOREX_API_KEY`はサーバー側だけに置き、`NEXT_PUBLIC_`で公開しないでください。
- `replyTo`には訪問者のアドレスを設定し、`from`は認証済みのドメインのままにします。
- ルートにレート制限をかけましょう。そうしないと、ボットがフォームを使って何千通ものメッセージを送ってきます。

### このページの内容

数分で最初のメールを送信

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

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

クレジットカード不要

## 続きを読む

[チュートリアル ### Node.jsでメールを送る方法（NodemailerとREST API） Node.jsからメールを送る2つの方法：SMTP経由のNodemailerか、シンプルなfetch呼び出し。動作するコード、エラー処理、DNS設定付き。 ガイドを読む](https://sendcorex.com/ja/blog/send-email-nodejs) [基礎 ### SMTPとは？わかりやすいガイド SMTPは、インターネットで送られるほぼすべてのメールを運ぶプロトコルです。RFCの専門用語を使わずに、実際に何をしているのかをステップごとに解説します。 ガイドを読む](https://sendcorex.com/ja/blog/what-is-smtp) [基礎 ### トランザクションメールとマーケティングメール：分けることが大切な理由 パスワードリセットとプロモーションの一斉送信は、同じ種類のメールではありません。同じように送ると、最も重要なメッセージが届かなくなることがあります。 ガイドを読む](https://sendcorex.com/ja/blog/transactional-vs-marketing-email)

数分で最初のメールを送信

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

クレジットカード不要

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