Sendcorex

การส่งถึงกล่องจดหมาย

การเข้ากล่องจดหมาย+62%

98.4%

Gmail
Outlook
Yahoo

อีเมลของคุณเข้ากล่องจดหมาย ไม่ใช่ถังสแปม

ตรวจติดตามการส่งถึงฟรีในทุกแพ็กเกจ

ดูเพิ่มเติม
บทเรียน

ส่งอีเมลจาก Next.js (App Router และ Route Handler)

วิธีของ App Router: Server Action เรียก REST API โดยตรง ไม่ต้องใช้ไคลเอนต์ SMTP

โดยทีม Sendcorex·อัปเดต 21 ก.ย. 2026·อ่าน 8 นาที

ทำไมที่นี่ใช้ REST แทน SMTP

การ deploy Next.js ส่วนใหญ่ทำงานบนฟังก์ชัน serverless หรือ edge ซึ่งการเชื่อมต่อ SMTP ขาออกที่ยาวนานไม่เสถียรหรือถูกบล็อกทั้งหมด การส่ง HTTPS POST ครั้งเดียวจาก Server Action เลี่ยงปัญหานี้ได้ทั้งหมด

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 เป็น HTML ด้วย @react-email/render แล้วส่งผลลัพธ์เป็น html ใน body คำขอ เทมเพลตจะยังเป็นคอมโพเนนต์แทนการต่อสตริง

เช็กลิสต์

  • เก็บ SENDCOREX_API_KEY ไว้ฝั่งเซิร์ฟเวอร์เท่านั้น อย่าเปิดเผยผ่าน NEXT_PUBLIC_
  • ตั้ง replyTo เป็นที่อยู่ของผู้เยี่ยมชม และใช้ from บนโดเมนที่ยืนยันแล้ว
  • จำกัดอัตราการเรียก route ไม่อย่างนั้นบอตจะใช้ฟอร์มส่งข้อความหาคุณเป็นพันๆ ฉบับ

ส่งอีเมลแรกในไม่กี่นาที

สร้างบัญชีฟรี ยืนยันโดเมน แล้ววางโค้ดด้านบน

ไม่ต้องใช้บัตรเครดิต