Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
W przypadku klientów innych niż Gmail obsługujemy standardowe protokoły IMAP, POP i SMTP. Serwery Gmaila IMAP, POP i SMTP zostały rozszerzone o obsługę autoryzacji za pomocą standardowego protokołu OAuth 2.0.
Protokół
Protokoły IMAP, POP i SMTP używają standardowej warstwy SASL (Simple Authentication and Security Layer), która do uwierzytelniania użytkowników wykorzystuje wbudowane natywne polecenia IMAP AUTHENTICATE, POP AUTH i SMTP AUTH. Mechanizm SASL XOAUTH2 umożliwia klientom podawanie danych logowania OAuth 2.0 na potrzeby uwierzytelniania. W dokumentacji protokołu SASL XOAUTH2 szczegółowo opisano mechanizm SASL XOAUTH2. Dostępne są też biblioteki i przykłady, w których zaimplementowano ten protokół.
Połączenia przychodzące z serwerem IMAP pod adresem imap.gmail.com:993 i serwerem POP pod adresem pop.gmail.com:995 wymagają protokołu SSL. Serwer SMTP poczty wychodzącej, smtp.gmail.com, obsługuje TLS. Jeśli klient zaczyna od zwykłego tekstu, przed wydaniem polecenia STARTTLS użyj portu 465 (w przypadku SSL) lub portu 587 (w przypadku TLS).
Limity długości sesji
Sesje POP w Gmailu są ograniczone do około 7 dni. Sesje IMAP Gmaila są ograniczone do około 24 godzin. Jeśli sesja została uwierzytelniona przy użyciu danych logowania OAuth, jest ona ograniczona do okresu ważności użytego tokena dostępu (zwykle 1 godziny). Sesja w tym kontekście to jedno ciągłe połączenie TCP.
Gdy czas minie i sesja wygaśnie, Gmail zamknie połączenie z komunikatem o wygaśnięciu sesji. Następnie klient może ponownie nawiązać połączenie, ponownie się uwierzytelnić i kontynuować. Jeśli używasz OAuth, upewnij się, że używany token dostępu jest prawidłowy (jeśli spróbujesz użyć tokena dostępu starszego niż 1 godzina, może on być nieprawidłowy).
Biblioteki i przykłady
Dostęp do poczty za pomocą protokołu IMAP lub POP oraz wysyłanie poczty za pomocą protokołu SMTP często odbywa się przy użyciu istniejących bibliotek IMAP i SMTP. Jeśli te biblioteki obsługują Simple Authentication and Security Layer (SASL), powinny być zgodne z mechanizmem SASL XOAUTH2 obsługiwanym przez Gmaila.
Na stronie Biblioteki i przykłady znajdziesz przykłady kodu w różnych popularnych językach, które korzystają z mechanizmu SASL XOAUTH2 z protokołami IMAP lub SMTP.
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 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."]]