EngageLab Email CLI

EngageLab Email CLI ช่วยให้ Agent และนักพัฒนาจัดการอีเมลขาเข้าและขาออกผ่าน command line ได้สะดวกขึ้น

ใช้สำหรับ:

  • แสดงรายการ mailbox ที่ใช้งานได้
  • แสดงและตรวจสอบ email thread
  • อ่านข้อความขาเข้า
  • polling ข้อความขาเข้าใหม่
  • ตอบกลับข้อความขาเข้า
  • ส่งอีเมลใหม่

ติดตั้ง

npm install -g @engagelabemail/cli
              
              npm install -g @engagelabemail/cli

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

ตรวจสอบเวอร์ชันที่ติดตั้ง:

engagelab-email-cli -V
              
              engagelab-email-cli -V

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

เมื่อรันคำสั่งที่เชื่อมต่อกับ EngageLab Email, CLI จะตรวจสอบว่ามีเวอร์ชันใหม่กว่าหรือไม่ หากจำเป็นต้องอัปเดต ระบบจะหยุดและแสดงคำสั่งอัปเดต:

npm install -g @engagelabemail/cli@latest
              
              npm install -g @engagelabemail/cli@latest

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

การตั้งค่า

จัดการการตั้งค่าที่บันทึกไว้

ใช้กลุ่มคำสั่ง config เพื่อบันทึก ตรวจสอบ หรือล้าง credentials ในเครื่อง

บันทึก service address และ Secret Key ไว้ในเครื่อง:

engagelab-email-cli config set --base-url http://localhost:8087 --secret-key sk_xxx
              
              engagelab-email-cli config set --base-url http://localhost:8087 --secret-key sk_xxx

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

ดูการตั้งค่าที่บันทึกไว้:

engagelab-email-cli config list
              
              engagelab-email-cli config list

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

ล้างการตั้งค่าที่บันทึกไว้:

engagelab-email-cli config clear
              
              engagelab-email-cli config clear

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

config list จะ mask ค่า Secret Key

ใช้ credentials แบบ global กับทุก business command

ไม่จำเป็นต้องบันทึก credentials ก่อน คุณสามารถส่ง --base-url และ --secret-key ตรงก่อน business command เช่น threads ... หรือ emails ... ได้เลย credentials จาก command line นี้จะมีผลเฉพาะคำสั่งปัจจุบัน และจะไม่เขียนทับค่าที่บันทึกไว้

ตัวอย่าง:

engagelab-email-cli --base-url http://localhost:8087 --secret-key sk_xxx threads get thread-1
              
              engagelab-email-cli --base-url http://localhost:8087 --secret-key sk_xxx threads get thread-1

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

เริ่มต้นใช้งานอย่างรวดเร็ว

แสดงรายการข้อความขาเข้าล่าสุด:

engagelab-email-cli emails receiving list --mailbox-id 12 --page-size 20
              
              engagelab-email-cli emails receiving list --mailbox-id 12 --page-size 20

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

อ่านข้อความขาเข้า 1 รายการ:

engagelab-email-cli emails receiving get <message-uid>
              
              engagelab-email-cli emails receiving get <message-uid>

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

ดู thread เต็มของข้อความ:

engagelab-email-cli threads messages <thread-id> --include-content --limit 10
              
              engagelab-email-cli threads messages <thread-id> --include-content --limit 10

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

ตอบกลับข้อความขาเข้า:

engagelab-email-cli emails receiving reply <message-uid> --subject "Re: Hello" --text "Thanks, we received your message."
              
              engagelab-email-cli emails receiving reply <message-uid> --subject "Re: Hello" --text "Thanks, we received your message."

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

ส่งอีเมลใหม่:

engagelab-email-cli emails send \ --mailbox-id 1001 \ --to alice@example.com \ --subject "Hello" \ --text "Hello from EngageLab Email CLI."
              
              engagelab-email-cli emails send \
  --mailbox-id 1001 \
  --to alice@example.com \
  --subject "Hello" \
  --text "Hello from EngageLab Email CLI."

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

สำหรับ script หรือ Agent ให้เพิ่ม --json เพื่อรับ output ที่เครื่องอ่านได้:

engagelab-email-cli emails receiving list --mailbox-id 12 --page-size 20 --json
              
              engagelab-email-cli emails receiving list --mailbox-id 12 --page-size 20 --json

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

คำสั่ง

config set

บันทึกการตั้งค่าในเครื่อง

Option คำอธิบาย
--base-url <url> Service address ค่าเริ่มต้นคือ ENGAGELAB_EMAIL_BASE_URL หากตั้งค่าไว้
--secret-key <key> Secret Key ค่าเริ่มต้นคือ ENGAGELAB_EMAIL_SECRET_KEY หากตั้งค่าไว้

ตัวอย่าง:

engagelab-email-cli config set --base-url http://localhost:8087 --secret-key sk_xxx
              
              engagelab-email-cli config set --base-url http://localhost:8087 --secret-key sk_xxx

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

config list

แสดงการตั้งค่าที่บันทึกไว้

ตัวอย่าง:

engagelab-email-cli config list
              
              engagelab-email-cli config list

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

config clear

ล้างการตั้งค่าที่บันทึกไว้ในเครื่อง รวมถึง baseUrl และ secretKey

ตัวอย่าง:

engagelab-email-cli config clear
              
              engagelab-email-cli config clear

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

mailbox list

แสดงรายการ mailbox ที่ใช้งานได้

Option คำอธิบาย
--mailbox <address> กรองตามที่อยู่ mailbox
--page-no <number> หมายเลขหน้า
--page-size <number> ขนาดหน้า
--json แสดงผลเป็น raw JSON

ตัวอย่าง:

engagelab-email-cli mailbox list --page-size 20
              
              engagelab-email-cli mailbox list --page-size 20

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

threads list

แสดงรายการ email thread

Option คำอธิบาย
--mailbox-id <id> กรองตาม mailbox ID
--subject <text> ค้นหาตาม subject ที่ถูก normalize แล้ว
--participant <email> ค้นหาตามผู้เข้าร่วม
--start-time <timestamp> เวลาเริ่มต้นของข้อความล่าสุด เป็นมิลลิวินาที
--end-time <timestamp> เวลาสิ้นสุดของข้อความล่าสุด เป็นมิลลิวินาที
--page-no <number> หมายเลขหน้า
--page-size <number> ขนาดหน้า
--json แสดงผลเป็น raw JSON

ตัวอย่าง:

engagelab-email-cli threads list --subject refund --page-no 1 --page-size 20
              
              engagelab-email-cli threads list --subject refund --page-no 1 --page-size 20

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

threads get <thread-id>

แสดง thread 1 รายการ

Argument/Option คำอธิบาย
<thread-id> Thread ID
--json แสดงผลเป็น raw JSON

ตัวอย่าง:

engagelab-email-cli threads get b0d9d6a1-1d17-4df8-8245-c807d7e8cb50
              
              engagelab-email-cli threads get b0d9d6a1-1d17-4df8-8245-c807d7e8cb50

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

threads messages <thread-id>

แสดงรายการข้อความใน thread

Argument/Option คำอธิบาย
<thread-id> Thread ID
--limit <number> จำนวนข้อความสูงสุด
--include-content รวม text/html/headers/attachments
--json แสดงผลเป็น raw JSON

ตัวอย่าง:

engagelab-email-cli threads messages b0d9d6a1-1d17-4df8-8245-c807d7e8cb50 --include-content --json
              
              engagelab-email-cli threads messages b0d9d6a1-1d17-4df8-8245-c807d7e8cb50 --include-content --json

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

emails receiving list

แสดงรายการข้อความขาเข้า

Option คำอธิบาย
--mailbox-id <id> กรองตาม mailbox ID
--keyword <text> คำค้นหา
--page-no <number> หมายเลขหน้า
--page-size <number> ขนาดหน้า
--json แสดงผลเป็น raw JSON

ตัวอย่าง:

engagelab-email-cli emails receiving list --keyword refund --page-size 20
              
              engagelab-email-cli emails receiving list --keyword refund --page-size 20

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

emails receiving get <message-uid>

แสดงข้อความขาเข้า 1 รายการ

Argument/Option คำอธิบาย
<message-uid> Message UID
--json แสดงผลเป็น raw JSON

ตัวอย่าง:

engagelab-email-cli emails receiving get 7e2b2de6-14c5-4ef1-a1e2-f4337e4606e2 --json
              
              engagelab-email-cli emails receiving get 7e2b2de6-14c5-4ef1-a1e2-f4337e4606e2 --json

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

emails receiving listen

Polling ข้อความขาเข้าใหม่ คำสั่งนี้จะทำงานต่อไปจนกว่าจะหยุดด้วย Ctrl+C

Option คำอธิบาย
--after <id> Cursor ID จากผลลัพธ์ก่อนหน้า
--limit <number> จำนวนข้อความสูงสุด
--interval <seconds> ระยะเวลา polling เป็นวินาที (ต่ำสุด 2)
--json แสดงผล 1 JSON ต่อบรรทัด

ตัวอย่าง:

engagelab-email-cli emails receiving listen --limit 10 --interval 5 --json
              
              engagelab-email-cli emails receiving listen --limit 10 --interval 5 --json

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

ดำเนินการต่อจาก cursor ที่ทราบ:

engagelab-email-cli emails receiving listen --after 1500 --limit 10 --interval 5 --json
              
              engagelab-email-cli emails receiving listen --after 1500 --limit 10 --interval 5 --json

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

emails receiving reply <message-uid>

ตอบกลับข้อความขาเข้า

Argument/Option คำอธิบาย
<message-uid> Message UID ที่ต้องการตอบกลับ
--subject <text> หัวข้อการตอบกลับ
--text <text> เนื้อหาธรรมดา (plain text)
--html <html> เนื้อหา HTML
--text-file <path> อ่านเนื้อหาธรรมดาจากไฟล์
--html-file <path> อ่านเนื้อหา HTML จากไฟล์
--cc <email> ที่อยู่ CC สามารถใช้ซ้ำได้
--bcc <email> ที่อยู่ BCC สามารถใช้ซ้ำได้
--reply-to <email> ที่อยู่ Reply-To สามารถใช้ซ้ำได้
--preview-text <text> ข้อความแสดงตัวอย่างอีเมล
--attachment <path> แนบไฟล์ในเครื่อง สามารถใช้ซ้ำได้ ต้องใช้คู่กับ --disposition สูงสุด 10 ไฟล์ รวมไม่เกิน 10MB หลัง base64 encoding (ประมาณ 7.5MB ไฟล์ดิบ)
--disposition <value> ประเภทไฟล์แนบ: attachment หรือ inline ต้องระบุเมื่อใช้ --attachment สามารถใช้ซ้ำหรือระบุครั้งเดียวสำหรับไฟล์แนบทั้งหมด
--content-id <id> Content-ID สำหรับไฟล์แนบรูปภาพแบบ inline ต้องระบุเมื่อใช้ --disposition inline กับไฟล์แนบรูปภาพ
--sandbox ส่งในโหมด sandbox
--json แสดงผลเป็น raw JSON

ตัวอย่าง:

engagelab-email-cli emails receiving reply 7e2b2de6-14c5-4ef1-a1e2-f4337e4606e2 \ --subject "Re: Refund update" \ --text "Thanks, we received your message." \ --attachment ./receipt.pdf \ --disposition attachment
              
              engagelab-email-cli emails receiving reply 7e2b2de6-14c5-4ef1-a1e2-f4337e4606e2 \
  --subject "Re: Refund update" \
  --text "Thanks, we received your message." \
  --attachment ./receipt.pdf \
  --disposition attachment

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

emails send

ส่งอีเมลใหม่

Option คำอธิบาย
--mailbox-id <id> Mailbox ID
--from <email> ที่อยู่อีเมลผู้ส่ง
--to <email> ที่อยู่อีเมลผู้รับ สามารถใช้ซ้ำได้
--subject <text> หัวข้ออีเมล
--text <text> เนื้อหาธรรมดา (plain text)
--html <html> เนื้อหา HTML
--text-file <path> อ่านเนื้อหาธรรมดาจากไฟล์
--html-file <path> อ่านเนื้อหา HTML จากไฟล์
--cc <email> ที่อยู่ CC สามารถใช้ซ้ำได้
--bcc <email> ที่อยู่ BCC สามารถใช้ซ้ำได้
--reply-to <email> ที่อยู่ Reply-To สามารถใช้ซ้ำได้
--preview-text <text> ข้อความแสดงตัวอย่างอีเมล
--attachment <path> แนบไฟล์ในเครื่อง สามารถใช้ซ้ำได้ ต้องใช้คู่กับ --disposition สูงสุด 10 ไฟล์ รวมไม่เกิน 10MB หลัง base64 encoding (ประมาณ 7.5MB ไฟล์ดิบ)
--disposition <value> ประเภทไฟล์แนบ: attachment หรือ inline ต้องระบุเมื่อใช้ --attachment สามารถใช้ซ้ำหรือระบุครั้งเดียวสำหรับไฟล์แนบทั้งหมด
--content-id <id> Content-ID สำหรับไฟล์แนบรูปภาพแบบ inline ต้องระบุเมื่อใช้ --disposition inline กับไฟล์แนบรูปภาพ
--sandbox ส่งในโหมด sandbox
--json แสดงผลเป็น raw JSON

ตัวอย่าง:

engagelab-email-cli emails send \ --mailbox-id 1001 \ --to alice@example.com \ --to bob@example.com \ --subject "Refund update" \ --text "Your refund has been processed." \ --attachment ./receipt.pdf \ --disposition attachment
              
              engagelab-email-cli emails send \
  --mailbox-id 1001 \
  --to alice@example.com \
  --to bob@example.com \
  --subject "Refund update" \
  --text "Your refund has been processed." \
  --attachment ./receipt.pdf \
  --disposition attachment

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

ส่ง HTML พร้อมไฟล์แนบรูปภาพแบบ inline:

engagelab-email-cli emails send --mailbox-id 1001 --to alice@example.com --subject "Inline image" --html "<p>Logo <img src=cid:image_1000></p>" --attachment ./logo.png --disposition inline --content-id image_1000
              
              engagelab-email-cli emails send --mailbox-id 1001 --to alice@example.com --subject "Inline image" --html "<p>Logo <img src=cid:image_1000></p>" --attachment ./logo.png --disposition inline --content-id image_1000

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

ข้อมูลเมตาของไฟล์แนบสามารถส่งได้ 2 รูปแบบที่เข้ากันได้ รูปแบบที่แนะนำจะผูกข้อมูลเมตากับแต่ละพาธไฟล์ ซึ่งช่วยหลีกเลี่ยงความคลุมเครือเมื่อมีไฟล์แนบหลายไฟล์:

engagelab-email-cli emails send --mailbox-id 1001 --to alice@example.com --subject "Mixed attachments" --html "<p>Logo <img src=cid:image_1000></p>" --attachment "./receipt.pdf;disposition=attachment" --attachment "./logo.png;disposition=inline;content_id=image_1000"
              
              engagelab-email-cli emails send --mailbox-id 1001 --to alice@example.com --subject "Mixed attachments" --html "<p>Logo <img src=cid:image_1000></p>" --attachment "./receipt.pdf;disposition=attachment" --attachment "./logo.png;disposition=inline;content_id=image_1000"

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

รูปแบบเดิมที่แยกตัวเลือกยังรองรับเพื่อความเข้ากันได้:

engagelab-email-cli emails send --mailbox-id 1001 --to alice@example.com --subject "Inline image" --html "<p>Logo <img src=cid:image_1000></p>" --attachment ./logo.png --disposition inline --content-id image_1000
              
              engagelab-email-cli emails send --mailbox-id 1001 --to alice@example.com --subject "Inline image" --html "<p>Logo <img src=cid:image_1000></p>" --attachment ./logo.png --disposition inline --content-id image_1000

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

อย่าผสมข้อมูลเมตาของไฟล์แนบแบบ inline (path;disposition=...) กับ --disposition หรือ --content-id ในคำสั่งเดียวกัน

ส่งเนื้อหา HTML จากไฟล์:

engagelab-email-cli emails send \ --mailbox-id 1001 \ --to alice@example.com \ --subject "Monthly report" \ --html-file ./report.html
              
              engagelab-email-cli emails send \
  --mailbox-id 1001 \
  --to alice@example.com \
  --subject "Monthly report" \
  --html-file ./report.html

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

การแสดงผล

โดยค่าเริ่มต้น CLI จะแสดงตารางหรือสรุปที่อ่านง่าย และแสดงข้อความ loading สั้นๆ ขณะที่ request กำลังทำงาน

ใช้ --json เมื่อมีเครื่องมือหรือ script อื่นต้องการ parse ผลลัพธ์

engagelab-email-cli emails receiving get <message-uid> --json
              
              engagelab-email-cli emails receiving get <message-uid> --json

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

emails receiving listen --json จะแสดงผล 1 JSON object ต่อบรรทัด

ข้อผิดพลาด

ข้อผิดพลาดที่มนุษย์อ่านได้จะรวมรหัสข้อผิดพลาดทางธุรกิจเมื่อ API ส่งกลับมา ตัวอย่างเช่น [100101] unauthorized

ข้อผิดพลาดแบบ --json มีรูปแบบดังนี้:

{ "error": { "code": "auth_error", "errorCode": 100101, "message": "unauthorized" } }
              
              {
  "error": {
    "code": "auth_error",
    "errorCode": 100101,
    "message": "unauthorized"
  }
}

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

Exit code:

Exit Code ความหมาย
1 พารามิเตอร์ผิดพลาดหรือ config ขาดหาย
2 การยืนยันตัวตนล้มเหลว
3 ไม่พบทรัพยากร
4 ข้อขัดแย้งหรือสถานะกำลังดำเนินการ
5 ข้อผิดพลาดของเซิร์ฟเวอร์หรือเครือข่าย
Icon Solid Transparent White Qiyu
ติดต่อฝ่ายขาย