> For the complete documentation index, see [llms.txt](https://docs.gpmautomate.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gpmautomate.com/automate-en/action-guides/mail/read-mail-code.md).

# Read mail code

Read mail code is an advanced action that allows the script to automatically log into the email inbox (Gmail, Outlook, Hotmail, Yahoo...) via the secure IMAP connection protocol. The system will automatically scan for the latest emails, search for emails from a specified sender, and extract the verification code (OTP/Code) to fill in on the website without you having to open the email tab for manual operation.

#### Explanation of configuration parameters:

* Email: Enter the email address to read the verification code (For example: `gpm_user@gmail.com`).
* Password: Enter the connection password.

  > ⚠️ Important note: For high-security email lines like Gmail, you must not enter the main account password here but must enter the App Password created specifically in the security settings of that email (Instructions for obtaining it are in the section below).
* Mail server: The IMAP server address of the email service provider.
  * *For example Gmail*: `imap.gmail.com`
  * *For example Outlook/Hotmail*: `outlook.office365.com`
* Email sent to contains: A keyword or email address that contains that phrase (Used to filter the correct email to find, for example: `noreply@pinterest.com` or `no-reply@pinterest`).
* Proxy: Optional IP configuration for logging into the mail server, helping to avoid being blocked by service providers (like Google, Microsoft) when operating a large number of accounts. You can set it up in 3 ways:
  * Leave blank: The system will use the original network (real machine IP) to perform the connection and retrieve the code.
  * Enter the variable `$profileProxy`: The script will automatically select the Proxy package assigned specifically for the current GPM Profile to use.
  * Manually enter proxy: Directly enter the Proxy string in a specific format (For example: `ip:port` or `ip:port:user:pass`) that you want to specify for this action.
* Code type: The format structure of the OTP code to be extracted. The system supports 3 options:
  1. Number: Use when the OTP code sent back is entirely a series of consecutive numbers (For example: `475997`).
     * *Code Length*: The exact length of the number sequence to extract (For example, if the code consists of 6 digits, enter `6`).
  2. Text: Use when the OTP code contains both letters and numbers interspersed or is hidden deep within an HTML structure tag of the email.
     * *Code element xpath*: The XPath path directly to the tag containing the OTP code within the email content (For example: `//h1` or `//span[@id="otp"]`).
     * *Code element attribute*: Enter the keyword `text` if the OTP code is directly between two tags (For example: `<h1>ABCDEF</h1>` ➔ Enter `text`). Or enter the *Attribute name* if the OTP code is hidden in the attribute of the tag (For example: `<h1 code="ABCDEF"></h1>` ➔ Enter `code`).
  3. Full: An advanced option that allows the system to extract the entire source code/text/HTML of the entire returned email into a variable. From there, you can pass this variable through Regex actions or Execute JS code to write your own flexible extraction algorithm as desired (Suitable for emails with extremely complex OTP structures).
* Output variable: The variable name that stores the verification code string (or the entire email content) after successful retrieval to pass into the next input action.

#### Instructions on how to Enable Two-Step Verification (2FA) and Obtain App Password for Gmail

For security, Google blocks all third-party applications from directly connecting to the inbox using the original password. You must follow the process below to grant GPM Automate access to IMAP:

**1. Enable Two-Step Verification (2FA) for your Google account**

1. Log in to your Google account, go to the account management page at: <https://myaccount.google.com>.
2. In the left menu, select Security.
3. Scroll down to the *"How you sign in to Google"*, find the Two-Step Verification option. If it is in the *Off* state, click on it and follow the instructions (linking a phone number or authentication app) to turn it on.

**2. Create and obtain App Password**

1. After successfully enabling Two-Step Verification, go to the App password section here: <https://myaccount.google.com/apppasswords>.
2. The App name field appears, enter any name to remember (For example: `GPM_Automate`) and then click Create.
3. A small window appears containing a 16-character yellow code (For example: `abcd efgh ijkl mnop`).
4. Copy all 16 characters (remove any spaces if present) and paste them directly into the Password field in the *Read mail code* action configuration of GPM Automate.

*(Note: For Outlook/Hotmail accounts, follow a similar process in Settings > Security > Advanced security options > App passwords to obtain the corresponding 16-character password string).*

<figure><img src="/files/TbmbkpHFj4w3rTtYIvbG" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.gpmautomate.com/automate-en/action-guides/mail/read-mail-code.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
