Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Para clientes que não são do Gmail, o Gmail é compatível com os protocolos padrão IMAP, POP e SMTP. Os servidores IMAP, POP e SMTP do Gmail foram estendidos para oferecer suporte à autorização pelo protocolo OAuth 2.0 padrão do setor.
Protocolo
O IMAP, o POP e o SMTP usam a Camada de Autenticação e Segurança Simples (SASL) padrão, com os comandos nativos IMAP AUTHENTICATE, POP AUTH e SMTP AUTH integrados para autenticar os usuários. O mecanismo SASL XOAUTH2 permite que os clientes forneçam credenciais do OAuth 2.0 para autenticação. A documentação do protocolo SASL XOAUTH2 descreve o mecanismo SASL XOAUTH2 em detalhes, e bibliotecas e exemplos que implementaram o protocolo estão disponíveis.
As conexões de entrada com o servidor IMAP em imap.gmail.com:993 e o servidor POP em pop.gmail.com:995 exigem SSL. O servidor SMTP de saída, smtp.gmail.com, é compatível com TLS. Se o cliente começar com texto simples, antes de emitir o comando STARTTLS, use a porta 465 (para SSL) ou 587 (para TLS).
Limites de duração da sessão
As sessões POP do Gmail são limitadas a cerca de sete dias. As sessões IMAP do Gmail são limitadas a cerca de 24 horas. Se a sessão foi autenticada usando credenciais do OAuth, ela fica limitada ao período de validade do token de acesso usado (geralmente uma hora). Uma sessão nesse contexto é uma conexão TCP contínua.
Quando o tempo expira e a sessão termina, o Gmail fecha a conexão com uma mensagem informando que a sessão expirou. Depois disso, o cliente pode se reconectar, autenticar novamente e continuar. Se você estiver usando o OAuth, verifique se o token de acesso usado é válido. Se você tentar usar um token de acesso com mais de uma hora, ele poderá ser inválido.
Bibliotecas e exemplos
O acesso e o envio de e-mails usando IMAP ou POP e SMTP geralmente são feitos com bibliotecas IMAP e SMTP existentes para maior conveniência. Desde que essas bibliotecas ofereçam suporte à camada de autenticação e segurança simples (SASL), elas serão compatíveis com o mecanismo SASL XOAUTH2 aceito pelo Gmail.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Não contém as informações de que eu preciso","missingTheInformationINeed","thumb-down"],["Muito complicado / etapas demais","tooComplicatedTooManySteps","thumb-down"],["Desatualizado","outOfDate","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Problema com as amostras / o código","samplesCodeIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 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."]]