IMAP, POP และ SMTP
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
สำหรับไคลเอ็นต์ที่ไม่ใช่ Gmail นั้น Gmail รองรับโปรโตคอล IMAP, POP และ SMTP มาตรฐาน เราได้ขยายเซิร์ฟเวอร์ IMAP, POP และ SMTP ของ Gmail เพื่อรองรับการให้สิทธิ์ผ่านโปรโตคอล OAuth 2.0 ซึ่งเป็นมาตรฐานอุตสาหกรรม
โปรโตคอล
IMAP, POP และ SMTP ใช้เลเยอร์การตรวจสอบสิทธิ์และความปลอดภัยอย่างง่าย (SASL) มาตรฐานโดยใช้คำสั่ง IMAP AUTHENTICATE
, POP AUTH
และ SMTP AUTH
ดั้งเดิมในตัวเพื่อตรวจสอบสิทธิ์ผู้ใช้ กลไก SASL XOAUTH2 ช่วยให้ไคลเอ็นต์ระบุข้อมูลเข้าสู่ระบบ OAuth 2.0 เพื่อการตรวจสอบสิทธิ์ได้ เอกสารประกอบโปรโตคอล SASL XOAUTH2 อธิบายกลไก SASL XOAUTH2 อย่างละเอียด และมีไลบรารีและตัวอย่างที่ใช้โปรโตคอลนี้
การเชื่อมต่อขาเข้ากับเซิร์ฟเวอร์ IMAP ที่ imap.gmail.com:993
และเซิร์ฟเวอร์ POP ที่ pop.gmail.com:995
ต้องใช้ SSL เซิร์ฟเวอร์ SMTP ขาออก smtp.gmail.com
รองรับ TLS หากไคลเอ็นต์เริ่มต้นด้วยข้อความธรรมดา ก่อนที่จะออกคำสั่ง STARTTLS ให้ใช้พอร์ต 465
(สำหรับ SSL) หรือพอร์ต 587
(สำหรับ TLS)
ขีดจำกัดระยะเวลาของเซสชัน
เซสชัน POP ของ Gmail มีระยะเวลาจำกัดประมาณ 7 วัน เซสชัน IMAP ของ Gmail จะจำกัดไว้ที่ประมาณ 24 ชั่วโมง หากเซสชันได้รับการตรวจสอบสิทธิ์โดยใช้ข้อมูลเข้าสู่ระบบ OAuth เซสชันจะจำกัดไว้ที่ระยะเวลาที่โทเค็นเพื่อการเข้าถึงที่ใช้มีผล (โดยปกติคือ 1 ชั่วโมง) เซสชันในบริบทนี้คือการเชื่อมต่อ TCP แบบต่อเนื่อง
เมื่อเวลาผ่านไปและเซสชันหมดอายุ Gmail จะปิดการเชื่อมต่อพร้อมข้อความที่ระบุว่าเซสชันหมดอายุแล้ว หลังจากนั้น ลูกค้าจะเชื่อมต่อใหม่ ตรวจสอบสิทธิ์อีกครั้ง และดำเนินการต่อได้ หากใช้ OAuth ให้ตรวจสอบว่าโทเค็นเพื่อการเข้าถึงที่ใช้ถูกต้อง (หากพยายามใช้โทเค็นเพื่อการเข้าถึงที่เก่ากว่า 1 ชั่วโมง โทเค็นอาจไม่ถูกต้อง)
ไลบรารีและตัวอย่าง
การเข้าถึงอีเมลโดยใช้ IMAP หรือ POP และการส่งอีเมลโดยใช้ SMTP มักจะทำโดยใช้ไลบรารี IMAP และ SMTP ที่มีอยู่เพื่อความสะดวก ตราบใดที่ไลบรารีเหล่านี้รองรับSimple Authentication and Security Layer (SASL) ก็ควรจะใช้ได้กับกลไก SASL XOAUTH2 ที่ Gmail รองรับ
นอกเหนือจากเอกสารประกอบเกี่ยวกับโปรโตคอล SASL XOAUTH2 แล้ว คุณอาจต้องอ่านการใช้ OAuth 2.0 เพื่อเข้าถึง Google APIs เพื่อดูข้อมูลเพิ่มเติมเกี่ยวกับการติดตั้งใช้งานไคลเอ็นต์ OAuth 2.0
หน้าไลบรารีและตัวอย่างมีตัวอย่างโค้ดในภาษาต่างๆ ที่ได้รับความนิยมโดยใช้กลไก SASL XOAUTH2 กับ IMAP หรือ SMTP
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-29 UTC
[null,null,["อัปเดตล่าสุด 2025-08-29 UTC"],[],[],null,["# IMAP, POP, and SMTP\n\nFor non-Gmail clients, Gmail supports the standard IMAP, POP, and SMTP protocols. The Gmail IMAP, POP, and SMTP servers have been extended to support authorization via the industry-standard OAuth 2.0 protocol.\n\nProtocol\n--------\n\nIMAP, POP, and SMTP use the standard [Simple Authentication and Security Layer (SASL)](https://tools.ietf.org/html/rfc4422), using the built-in the native IMAP `AUTHENTICATE`, POP `AUTH`, and SMTP `AUTH` commands, to authenticate users. The SASL XOAUTH2 mechanism enables clients to provide OAuth 2.0 credentials for authentication. The [SASL XOAUTH2 protocol documentation](/workspace/gmail/imap/xoauth2-protocol) describes the SASL XOAUTH2 mechanism in great detail, and [libraries and samples](/workspace/gmail/imap/xoauth2-libraries) which have implemented the protocol are available.\n\nIncoming connections to the IMAP server at `imap.gmail.com:993` and the POP server at `pop.gmail.com:995` require SSL. The outgoing SMTP server, `smtp.gmail.com`, supports TLS. If your client begins with plain text, before issuing the STARTTLS command, use port `465` (for SSL), or port `587` (for TLS).\n\nSession length limits\n---------------------\n\nGmail POP sessions are limited to about 7 days. Gmail IMAP sessions are limited to about 24 hours. If the session was authenticated using OAuth credentials, it's limited to about the validity period of the access token used (usually 1 hour). A session in this context is one continuous [TCP connection](https://en.wikipedia.org/wiki/Transmission_Control_Protocol).\n\nWhen the time elapses and the session expires, Gmail closes the connection with a message saying that the session expired. After that, the client can reconnect, authenticate again, and continue. If using OAuth, make sure that the access token used is valid (if you try to use an access token older than 1 hour, it might be invalid).\n\nLibraries and Samples\n---------------------\n\nAccessing mail using IMAP or POP and sending mail using SMTP is often done using existing IMAP and SMTP libraries for convenience. As long as these libraries support the [Simple Authentication and Security Layer (SASL)](https://tools.ietf.org/html/rfc4422), they should be compatible with the SASL XOAUTH2 mechanism supported by Gmail.\n\nIn addition to the SASL XOAUTH2 [protocol documentation](/workspace/gmail/imap/xoauth2-protocol), you may also want to read [Using OAuth 2.0 to Access Google APIs](https://developers.google.com/identity/protocols/OAuth2) for further information on implementing an OAuth 2.0 client.\n\nThe [Libraries and Samples](/workspace/gmail/imap/xoauth2-libraries) page provides code samples in a variety of popular languages using the SASL XOAUTH2 mechanism with either IMAP or SMTP."]]