# Email Processing

{% hint style="danger" %}
If you are not an active Apple Mail user yet, first setup Apple Mail, let it download all emails, and then enable the extension. Else all your emails will be sent to the AI provider.
{% endhint %}

To get started with email processing, you will need to enable the Apple Mail extension. Apple Mail is required for Inbox AI to be able to process email, but it can be running in the background while you using another email application if you prefer.

In Mail, go to "Settings", and then "Extensions", and check the Inbox AI extension.&#x20;

{% hint style="info" %}
Restart Apple mail after enabling the extension, else email processing will not work.
{% endhint %}

<figure><img src="/files/So4inZpb18YmY18lEuCu" alt=""><figcaption><p>Enable the Inbox AI extension to enable email processing</p></figcaption></figure>

After enabling, all incoming new email will be processed by Inbox AI. All processing happens on device, but email will be sent to your selected AI provider. You can disable processing, by unchecking the extension or by selecting "Do Nothing" as the email processor in the general settings.

<figure><img src="/files/ozdiOtcrLlPmuhkzvUyd" alt=""><figcaption><p>Apple Mail Extension settings</p></figcaption></figure>

Finally, you can customize the maximum age of incoming emails to process. To test the email processing, send yourself an email and wait for it to process. By default the "Process email" action is used to process incoming email. Let's check it out.

<figure><img src="/files/OeX31mw2DkH6B14CEbac" alt=""><figcaption><p>The process email action</p></figcaption></figure>

The process email is an [Ask AI](/inbox-ai/actions/custom-actions/ask-ai.md) action. The prompt is sent to the default AI provider you have chosen. The AI is given the ability to choose which action to call next, only these actions are available to the AI. In this example it has two options:

* [Send Notification](/inbox-ai/actions/built-in-actions/system-actions/send-notification.md)
* Pick a category

In the prompt, you can specify the behavior you are looking for. The `{{ value }}` placeholders in the prompt will be replaced by variables before sending them to the AI. In this case the `{{ originalInput | process }}` is the simplified incoming email, and your name is also inserted. For more information on templating, see the [Templating](/inbox-ai/templating.md) page.

When the AI picks an email category, it calls the category action. Open it in the sidebar to check it out.

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

This is a [Multiple Choice](/inbox-ai/actions/custom-actions/multiple-choice.md) action, it routes an incoming value another AI chose, to another action. Here you can see that "Junk" is linked to "Move to Junk". And, more interestingly, "Task" is linked to another [Ask AI](/inbox-ai/actions/custom-actions/ask-ai.md) action, that aims to extract tasks and add them to Apple Reminders.

You can change the behavior here, or build your own actions to fully control the behavior of the AI.

## Selecting which emails are sent to AI

If for any reason you want to ensure only specific emails go into an AI action, you can use the power of the [Templating](/inbox-ai/templating.md) in Inbox AI. Below is an example for a prompt that achieves this.

{% hint style="warning" %}
Check each Ask AI action in the chain to ensure your email does not get inserted into a later AI request prompt.
{% endhint %}

```
{% if originalInput | match: "To:.*hello@example\.com" %}
Categorize this email I ({{ settings.name }}) received below.

Email:
{{ originalInput | process }}
{% endif %}
```

The conditional if statement only returns a prompt when the originalInput has a line that matches the "To:" email header. Note that the match is a regular expression. It goes beyond this guide to explain these, but ChatGPT can help. Check the [Logging](/inbox-ai/logging.md) to see what is sent to the AI.

{% hint style="info" %}
Empty prompts will not trigger an actual request to the AI and are assumed to be a signal that the AI should do nothing.
{% endhint %}


---

# Agent Instructions: 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:

```
GET https://dreetje-1.gitbook.io/inbox-ai/email-processing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
