Odoo Outgoing Mail Server — Gmail

🇹🇭 ภาษาไทย

ขั้นตอนตั้งค่า Odoo ให้ส่งอีเมลผ่าน Gmail (Google Workspace หรือ Gmail ส่วนตัว) แบบละเอียด ตั้งแต่ต้นจนเทส Connection สำเร็จ

ดูภาพรวมการตั้งค่าอีเมลทั้งหมด → Odoo Email Configuration


สิ่งที่ต้องมีก่อน

รายการรายละเอียด
Gmail accountบัญชีที่จะใช้ส่งอีเมล (เช่น [email protected])
2-Step Verificationต้องเปิดก่อนถึงจะสร้าง App Password ได้
App Password16-digit token สำหรับ Odoo (ไม่ใช่ password ปกติ)
Odoo Developer Modeต้องเปิดก่อนเห็นเมนู Technical

ขั้นตอนที่ 1 — เปิด 2-Step Verification บน Gmail

  1. ไปที่ myaccount.google.com
  2. Security2-Step Verification
  3. กด Get started → ทำตามขั้นตอนจนเปิดสำเร็จ

ถ้าเปิดอยู่แล้วข้ามไปขั้นตอนที่ 2 ได้เลย


ขั้นตอนที่ 2 — สร้าง App Password

  1. ไปที่ myaccount.google.com
  2. Security2-Step Verification → เลื่อนลงหา App passwords
  3. ช่อง App name → พิมพ์ Odoo SMTP (หรือชื่ออะไรก็ได้)
  4. กด Create
  5. บันทึก 16-digit token ที่ได้ไว้ให้ดี — แสดงครั้งเดียว ปิดแล้วดูไม่ได้อีก
ตัวอย่าง App Password:
abcd efgh ijkl mnop
(16 ตัวอักษร — ตอนใส่ใน Odoo ลบ space ออกได้เลย)

Google Workspace: ถ้า Admin ปิด App Passwords ไว้ → Admin Console → Security → Less secure apps → เปิดให้ user


ขั้นตอนที่ 3 — เปิด Developer Mode ใน Odoo

Settings → (scroll ล่างสุด) → Activate the developer mode

หรือเร็วกว่า: เพิ่ม ?debug=1 ต่อท้าย URL ใดก็ได้


ขั้นตอนที่ 4 — เปิด Custom Email Servers

Settings → General Settings → Discuss
  ☑ Use Custom Email Servers
→ Save

ขั้นตอนที่ 5 — เพิ่ม Outgoing Mail Server

Path: Settings → Technical → Email → Outgoing Mail Servers → New

ใส่ค่าดังนี้:

Fieldค่าสำหรับ Gmail
NameGmail SMTP (หรือชื่อที่ต้องการ)
SMTP Serversmtp.gmail.com
SMTP Port587
Connection SecuritySTARTTLS
Usernameอีเมล Gmail เต็ม เช่น [email protected]
PasswordApp Password 16 หลัก (ไม่ใช่ password Gmail ปกติ)
Priority10 (default)

→ กด Save

→ กด Test Connection

ผลลัพธ์ที่คาดหวัง:

  • Connection Test Succeeded! = ตั้งค่าถูกต้อง
  • ❌ Error → ดู Troubleshooting ด้านล่าง

ขั้นตอนที่ 6 — ตั้ง Default From Address (แนะนำ)

เพื่อให้อีเมลทุกฉบับออกจาก address เดียวกัน:

Settings → General Settings → Discuss
  Default From Email: [email protected]
→ Save

ขั้นตอนที่ 7 — ตั้งค่า DNS เพื่อป้องกัน Spam (สำคัญมาก)

ถ้าส่งจาก custom domain เช่น yourcompany.com ต้องตั้ง DNS:

SPF Record

TXT  @  "v=spf1 include:_spf.google.com include:_spf.odoo.com mx ~all"

DKIM Record

ดึง key จาก Gmail:

Google Admin Console → Apps → Google Workspace → Gmail
→ Authenticate email → Generate new record

แล้วนำ TXT record ไปเพิ่มที่ DNS ของ domain

DMARC Record

TXT  _dmarc  "v=DMARC1; p=quarantine; rua=mailto:[email protected]"

✅ ตั้ง SPF + DKIM ก่อนใช้งานจริงเสมอ — ถ้าไม่มีอีเมลจาก Odoo จะตก Spam


Troubleshooting Gmail

อาการสาเหตุวิธีแก้
Authentication failedใส่ password Gmail ปกติต้องใช้ App Password เท่านั้น
App passwords ไม่มีให้กดยังไม่ได้เปิด 2-Step Verificationเปิด 2FA ก่อน
App Password option หายไปGoogle Workspace Admin ปิดไว้แจ้ง Admin เปิด App Passwords
Connection refused on port 587Firewall blockลอง port 465 + SSL/TLS แทน
ส่งได้แต่ตก SpamSPF/DKIM ยังไม่ตั้งเพิ่ม DNS records
ส่งได้แต่ชื่อผู้ส่งไม่ถูกDefault From ไม่ได้ตั้งตั้ง Default From Address
อีเมลค้างใน queueScheduled action หยุดSettings → Technical → Automation → Scheduled Actions → เช็ค Email Queue Manager

ดู Email ที่ส่งออกไปแล้ว

Settings → Technical → Email → Emails

ดู status:

  • Sent = ส่งสำเร็จ
  • In Queue = รอส่ง
  • Exception = error → กดดูเพื่ออ่าน error message

สรุปขั้นตอนแบบย่อ

1. Gmail: เปิด 2FA → สร้าง App Password (16 หลัก)
2. Odoo: เปิด Developer Mode
3. Odoo: Settings → General Settings → Discuss → ☑ Use Custom Email Servers
4. Odoo: Settings → Technical → Email → Outgoing Mail Servers → New
          SMTP: smtp.gmail.com | Port: 587 | STARTTLS
          Username: [email protected] | Password: [App Password]
5. Test Connection → ✅
6. ตั้ง SPF/DKIM DNS records


🇬🇧 English

Step-by-step guide to configure Odoo to send email via Gmail (Google Workspace or personal Gmail).

For the full email configuration overview → Odoo Email Configuration


Prerequisites

ItemDetails
Gmail accountThe account that will send emails (e.g. [email protected])
2-Step VerificationMust be enabled before you can create an App Password
App Password16-character token for Odoo (NOT your normal Gmail password)
Odoo Developer ModeRequired to access the Technical menu

Step 1 — Enable 2-Step Verification on Gmail

  1. Go to myaccount.google.com
  2. Security2-Step Verification
  3. Click Get started and complete the setup

Skip to Step 2 if 2-Step Verification is already on


Step 2 — Create an App Password

  1. Go to myaccount.google.com
  2. Security2-Step Verification → scroll down to App passwords
  3. App name → type Odoo SMTP (any name works)
  4. Click Create
  5. Save the 16-character token — it is shown only once
Example App Password:
abcd efgh ijkl mnop
(spaces can be removed when entering in Odoo)

Google Workspace: If App Passwords are disabled by admin → Admin Console → Security → Less secure apps → enable for users


Step 3 — Enable Developer Mode in Odoo

Settings → (scroll to bottom) → Activate the developer mode

Or append ?debug=1 to any Odoo URL.


Step 4 — Enable Custom Email Servers

Settings → General Settings → Discuss
  ☑ Use Custom Email Servers
→ Save

Step 5 — Add Outgoing Mail Server

Path: Settings → Technical → Email → Outgoing Mail Servers → New

FieldValue for Gmail
NameGmail SMTP
SMTP Serversmtp.gmail.com
SMTP Port587
Connection SecuritySTARTTLS
UsernameFull Gmail address e.g. [email protected]
Password16-character App Password
Priority10 (default)

→ Click Save

→ Click Test Connection

  • Connection Test Succeeded! = configured correctly
  • ❌ Error → see Troubleshooting below

Settings → General Settings → Discuss
  Default From Email: [email protected]
→ Save

Step 7 — DNS Records to Prevent Spam

Required if sending from a custom domain:

# SPF
TXT  @         "v=spf1 include:_spf.google.com include:_spf.odoo.com mx ~all"
 
# DKIM — get key from Google Admin Console → Gmail → Authenticate email
TXT  google._domainkey  "v=DKIM1; k=rsa; p=YOUR_PUBLIC_KEY"
 
# DMARC
TXT  _dmarc    "v=DMARC1; p=quarantine; rua=mailto:[email protected]"

Troubleshooting

SymptomCauseFix
Authentication failedUsing Gmail login passwordMust use App Password
No App passwords option2-Step Verification not enabledEnable 2FA first
App Password option missingGoogle Workspace admin disabled itAsk admin to allow App Passwords
Connection refused on port 587Firewall blockingTry port 465 + SSL/TLS
Emails land in spamSPF/DKIM not configuredAdd DNS records
Wrong sender nameDefault From not setSet Default From Address
Emails stuck in queueScheduled action stoppedCheck Email Queue Manager in Scheduled Actions

Check Sent Emails

Settings → Technical → Email → Emails

Filter by status: Sent / In Queue / Exception


Quick Reference

1. Gmail: Enable 2FA → Create App Password (16 chars)
2. Odoo: Enable Developer Mode
3. Odoo: Settings → General Settings → Discuss → ☑ Use Custom Email Servers
4. Odoo: Settings → Technical → Email → Outgoing Mail Servers → New
          SMTP: smtp.gmail.com | Port: 587 | STARTTLS
          Username: [email protected] | Password: [App Password]
5. Test Connection → ✅
6. Set SPF/DKIM DNS records