This document explains how to manage POP and IMAP protocols using the
Gmail API.

POP and IMAP are two ways to read your Gmail messages in other email
clients. POP is an older protocol designed for a single computer. With POP, your
client downloads messages, and you choose how often to download new ones. IMAP
works across multiple devices and syncs messages in real time.

You can use the
[`settings`](https://developers.google.com/workspace/gmail/api/reference/rest/v1/users.settings) resource of
the Gmail API to configure how Gmail handles POP and
IMAP protocols:

- [`settings.getPop`](https://developers.google.com/workspace/gmail/api/reference/rest/v1/users.settings/getPop)
- [`settings.updatePop`](https://developers.google.com/workspace/gmail/api/reference/rest/v1/users.settings/updatePop)
- [`settings.getImap`](https://developers.google.com/workspace/gmail/api/reference/rest/v1/users.settings/getImap)
- [`settings.updateImap`](https://developers.google.com/workspace/gmail/api/reference/rest/v1/users.settings/updateImap)

## POP

You can manage POP settings for an account using the
[`PopSettings`](https://developers.google.com/workspace/gmail/api/reference/rest/v1/PopSettings) object.

### Enable and disable access

Control access with the
[`accessWindow`](https://developers.google.com/workspace/gmail/api/reference/rest/v1/PopSettings#FIELDS.access_window)
field. This field determines whether POP is enabled and which messages the API
retrieves.

| Value | Effect |
|---|---|
| `disabled` | No messages are accessible through POP |
| `allMail` | All unfetched messages are accessible through POP |
| `fromNowOn` | Only new messages are accessible through POP |

### Message disposition

Configure the disposition of messages that the API retrieves with the
[`disposition`](https://developers.google.com/workspace/gmail/api/reference/rest/v1/PopSettings#FIELDS.disposition)
field.

| Value | Effect |
|---|---|
| `archive` | Move messages out of the `INBOX` |
| `leaveInInbox` | Do nothing; leave messages unread in the `INBOX` |
| `markRead` | Leave messages in the `INBOX` and mark them as read |
| `trash` | Move messages to the `TRASH` |

## IMAP

You can manage IMAP settings for an account using the
[`ImapSettings`](https://developers.google.com/workspace/gmail/api/reference/rest/v1/ImapSettings) object.

### Enable and disable access

Use the boolean
[`enabled`](https://developers.google.com/workspace/gmail/api/reference/rest/v1/ImapSettings#FIELDS.enabled)
field to control access. This field determines whether IMAP is enabled for the
account.

### Message disposition

Use the
[`expungeBehavior`](https://developers.google.com/workspace/gmail/api/reference/rest/v1/ImapSettings#FIELDS.expunge_behavior)
field to configure the disposition of a message when a client marks it as
deleted and expunges it from the last visible IMAP folder.

| Value | Effect |
|---|---|
| `archive` | Move messages marked as deleted out of the `INBOX` |
| `deleteForever` | Permanently delete messages marked as deleted |
| `trash` | Move messages marked as deleted to the `TRASH` |

If the boolean
[`autoExpunge`](https://developers.google.com/workspace/gmail/api/reference/rest/v1/ImapSettings#FIELDS.auto_expunge)
field is `true`, Gmail immediately expunges a message when a
client marks it as deleted in IMAP. Otherwise, messages remain until the IMAP
client explicitly requests their removal.

## Related topics

- [IMAP, POP, and SMTP for the Gmail IMAP API](https://developers.google.com/workspace/gmail/imap/imap-smtp)
- [Choose your IMAP email client settings for Gmail](https://support.google.com/mail/answer/78892)
- [Read Gmail messages on other email clients using POP](https://support.google.com/mail/answer/7104828)