Оптимизируйте свои подборки
Сохраняйте и классифицируйте контент в соответствии со своими настройками.
Для клиентов, не являющихся Gmail, Gmail поддерживает стандартные протоколы IMAP, POP и SMTP. Серверы Gmail IMAP, POP и SMTP были расширены для поддержки авторизации по стандартному протоколу OAuth 2.0.
Входящие соединения с IMAP-сервером imap.gmail.com:993 и POP-сервером pop.gmail.com:995 требуют SSL. Исходящий SMTP-сервер smtp.gmail.com поддерживает TLS. Если ваш клиент начинает с простого текста, перед выполнением команды STARTTLS используйте порт 465 (для SSL) или порт 587 (для TLS).
Ограничения по продолжительности сеанса
Продолжительность сеансов Gmail POP ограничена примерно 7 днями. Продолжительность сеансов Gmail IMAP ограничена примерно 24 часами. Если сеанс был аутентифицирован с использованием учётных данных OAuth, он ограничен примерно сроком действия используемого токена доступа (обычно 1 часом). В данном контексте сеанс — это одно непрерывное TCP-соединение .
По истечении этого времени и завершении сеанса Gmail закрывает соединение, выводя сообщение об окончании сеанса. После этого клиент может повторно подключиться, пройти аутентификацию и продолжить работу. При использовании OAuth убедитесь, что используемый токен доступа действителен (если вы попытаетесь использовать токен доступа старше 1 часа, он может быть недействителен).
Библиотеки и образцы
Доступ к почте по протоколам IMAP или POP и отправка почты по протоколу SMTP часто осуществляются с использованием существующих библиотек IMAP и SMTP для удобства. Если эти библиотеки поддерживают протокол SASL (Simple Authentication and Security Layer) , они должны быть совместимы с механизмом SASL XOAUTH2, поддерживаемым Gmail.
На странице «Библиотеки и примеры» представлены образцы кода на различных популярных языках с использованием механизма SASL XOAUTH2 с протоколами IMAP или SMTP.
[[["Прост для понимания","easyToUnderstand","thumb-up"],["Помог мне решить мою проблему","solvedMyProblem","thumb-up"],["Другое","otherUp","thumb-up"]],[["Отсутствует нужная мне информация","missingTheInformationINeed","thumb-down"],["Слишком сложен/слишком много шагов","tooComplicatedTooManySteps","thumb-down"],["Устарел","outOfDate","thumb-down"],["Проблема с переводом текста","translationIssue","thumb-down"],["Проблемы образцов/кода","samplesCodeIssue","thumb-down"],["Другое","otherDown","thumb-down"]],["Последнее обновление: 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."]]