การเชื่อมต่อ
การส่งผ่าน SMTP Submission (พอร์ต 587)
ตั้งค่า SMTP STARTTLS พอร์ต 587 สำหรับ Nodemailer, Python, Laravel และแอปพลิเคชันทั่วไป
ค่าการเชื่อมต่อ SMTP
| พารามิเตอร์ | ค่าใช้งานจริง (Production) | ค่าสำหรับ Local Dev |
|---|---|---|
| Host | smtp.mailcraft.local |
localhost |
| Port | 587 |
2525 |
| Encryption | STARTTLS (บังคับก่อน AUTH) | Optional (SMTP_ALLOW_INSECURE_AUTH=true) |
| Authentication | AUTH PLAIN หรือ AUTH LOGIN |
AUTH PLAIN / LOGIN |
| Username / Password | สร้างจากหน้า Mail Agents | สร้างจากหน้า Mail Agents |
กฎความปลอดภัยของเซิร์ฟเวอร์ SMTP
- บังคับ STARTTLS ก่อน AUTH: ในโหมด Production เซิร์ฟเวอร์จะไม่ประกาศคำสั่ง
AUTHจนกว่าจะยกระดับการเชื่อมต่อด้วยSTARTTLSสำเร็จ - ป้องกันการปลอมโดเมนข้าม Tenant: ทั้งโดเมนของ Envelope
MAIL FROMและ HeaderFrom:ต้องเป็นโดเมนที่ผูกอยู่กับ Mail Agent เดียวกัน มิฉะนั้นจะถูกปฏิเสธด้วย550 5.7.1 - หักเครดิตอัตโนมัติเมื่อจบคำสั่ง DATA: หากยอดเครดิตไม่พอ ระบบจะตอบ
550 5.7.0 Insufficient creditsและไม่นำเข้าคิวส่ง
ตัวอย่าง: Node.js (Nodemailer)
import nodemailer from 'nodemailer';
const transporter = nodemailer.createTransport({
host: 'smtp.mailcraft.local',
port: 587,
secure: false, // ใช้ STARTTLS บนพอร์ต 587
requireTLS: true,
auth: {
user: 'smtp_agent_username',
pass: 'YOUR_SMTP_PASSWORD',
},
});
await transporter.sendMail({
from: '"Example App" <no-reply@mail.example.com>',
to: 'customer@example.org',
subject: 'ใบเสร็จรับเงิน',
text: 'ขอบคุณที่ใช้บริการ',
html: '<p>ขอบคุณที่ใช้บริการ</p>',
});
ตัวอย่าง: Python (smtplib)
import smtplib
from email.message import EmailMessage
msg = EmailMessage()
msg["Subject"] = "Password Reset"
msg["From"] = "no-reply@mail.example.com"
msg["To"] = "user@example.org"
msg.set_content("Click the link to reset your password.")
with smtplib.SMTP("smtp.mailcraft.local", 587) as server:
server.starttls()
server.login("smtp_agent_username", "YOUR_SMTP_PASSWORD")
server.send_message(msg)