Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Đối với các ứng dụng không phải Gmail, Gmail hỗ trợ các giao thức IMAP, POP và SMTP tiêu chuẩn. Các máy chủ IMAP, POP và SMTP của Gmail đã được mở rộng để hỗ trợ việc uỷ quyền thông qua giao thức OAuth 2.0 theo tiêu chuẩn ngành.
Giao thức
IMAP, POP và SMTP sử dụng Lớp xác thực và bảo mật đơn giản (SASL) tiêu chuẩn, sử dụng các lệnh IMAP AUTHENTICATE, POP AUTH và SMTP AUTH gốc được tích hợp sẵn để xác thực người dùng. Cơ chế SASL XOAUTH2 cho phép ứng dụng cung cấp thông tin đăng nhập OAuth 2.0 để xác thực. Tài liệu về giao thức SASL XOAUTH2 mô tả cơ chế SASL XOAUTH2 một cách chi tiết và có sẵn các thư viện và mẫu đã triển khai giao thức này.
Các kết nối đến máy chủ IMAP tại imap.gmail.com:993 và máy chủ POP tại pop.gmail.com:995 đều yêu cầu SSL. Máy chủ SMTP gửi đi, smtp.gmail.com, hỗ trợ TLS. Nếu máy khách của bạn bắt đầu bằng văn bản thuần tuý, trước khi đưa ra lệnh STARTTLS, hãy sử dụng cổng 465 (đối với SSL) hoặc cổng 587 (đối với TLS).
Giới hạn thời lượng phiên
Các phiên POP của Gmail chỉ kéo dài khoảng 7 ngày. Các phiên IMAP của Gmail bị giới hạn trong khoảng 24 giờ. Nếu phiên được xác thực bằng thông tin đăng nhập OAuth, thì phiên đó sẽ bị giới hạn trong khoảng thời gian hiệu lực của mã truy cập được dùng (thường là 1 giờ). Trong ngữ cảnh này, một phiên là một kết nối TCP liên tục.
Khi hết thời gian và phiên hết hạn, Gmail sẽ đóng kết nối bằng một thông báo cho biết phiên đã hết hạn. Sau đó, ứng dụng có thể kết nối lại, xác thực lại và tiếp tục. Nếu bạn đang sử dụng OAuth, hãy đảm bảo rằng mã truy cập bạn dùng là hợp lệ (nếu bạn cố gắng dùng mã truy cập cũ hơn 1 giờ, thì mã đó có thể không hợp lệ).
Thư viện và mẫu
Việc truy cập vào thư bằng IMAP hoặc POP và gửi thư bằng SMTP thường được thực hiện bằng các thư viện IMAP và SMTP hiện có để thuận tiện. Miễn là các thư viện này hỗ trợ Lớp xác thực và bảo mật đơn giản (SASL), chúng sẽ tương thích với cơ chế SASL XOAUTH2 mà Gmail hỗ trợ.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 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."]]