From 13d0d1c19580cce81f510a0394a03838615de870 Mon Sep 17 00:00:00 2001 From: Rami Mosleh Date: Mon, 9 Jan 2023 10:05:11 +0200 Subject: [PATCH 1/2] Add config flow to IMAP integration Update documentation for IMAP integration now supporting config flow. --- source/_integrations/imap.markdown | 100 ++++++++--------------------- 1 file changed, 25 insertions(+), 75 deletions(-) diff --git a/source/_integrations/imap.markdown b/source/_integrations/imap.markdown index 359432a28b06..90174f46594d 100644 --- a/source/_integrations/imap.markdown +++ b/source/_integrations/imap.markdown @@ -9,65 +9,18 @@ ha_domain: imap ha_platforms: - sensor ha_integration_type: integration +ha_codeowners: + - '@engrbm87' +ha_config_flow: true --- -The `imap` integration is observing your [IMAP server](https://en.wikipedia.org/wiki/Internet_Message_Access_Protocol) and reporting the amount of unread emails. +The `imap` integration is observing your [IMAP server](https://en.wikipedia.org/wiki/Internet_Message_Access_Protocol) and reporting the amount of unread emails. Other search criteria can be used as shown in the example below. -## Configuration - -To enable this sensor, add the following lines to your `configuration.yaml` file: - -```yaml -# Example configuration.yaml entry -sensor: - - platform: imap - server: YOUR_IMAP_SERVER - username: YOUR_USERNAME - password: YOUR_PASSWORD -``` - -{% configuration %} -server: - description: The IP address or hostname of the IMAP server. - required: true - type: string -port: - description: The port where the server is accessible. - required: false - default: 993 - type: integer -name: - description: Name of the IMAP sensor. - required: false - type: string -username: - description: Username for the IMAP server. - required: true - type: string -password: - description: Password for the IMAP server. - required: true - type: string -folder: - description: The IMAP folder to watch. - required: false - default: inbox - type: string -search: - description: The IMAP search to perform on the watched folder. - required: false - default: UnSeen UnDeleted - type: string -charset: - description: The character set used for this connection. - required: false - default: utf-8 - type: string -{% endconfiguration %} +{% include integrations/config_flow.md %} ### Gmail with App Password -If you’re going to use Gmail, it’s always good practice to create a [App Password](https://support.google.com/mail/answer/185833). +If you’re going to use Gmail, you need to create a [App Password](https://support.google.com/mail/answer/185833). 1. Go to your [Google Account](https://myaccount.google.com/) 2. Select **Security** @@ -84,27 +37,24 @@ By default, this integration will count unread emails. By configuring the search * `FROM`, `TO`, `SUBJECT` to find emails in a folder (see [IMAP RFC for all standard options](https://tools.ietf.org/html/rfc3501#section-6.4.4)) * [Gmail's IMAP extensions](https://developers.google.com/gmail/imap/imap-extensions) allow raw Gmail searches, like `X-GM-RAW "in: inbox older_than:7d"` to show emails older than one week in your inbox. Note that raw Gmail searches will ignore your folder configuration and search all emails in your account! -#### Full configuration sample with search - -```yaml -# Example configuration.yaml entry for gmail -sensor: - - platform: imap - server: imap.gmail.com - port: 993 - username: YOUR_USERNAME - password: YOUR_PASSWORD - search: FROM , SUBJECT - # Or use X-GM-RAW search-term like this, to find unread emails from the last 7 days in your inbox - # search: 'X-GM-RAW "in: inbox newer_than:7d is:unread"' +#### Config entry sample with search examples -# Example configuration.yaml entry for Office 365 -sensor: - - platform: imap - server: outlook.office365.com - port: 993 - username: email@address.com - password: password - search: FROM , SUBJECT - charset: US-ASCII +``` + server: imap.gmail.com + port: 993 + username: YOUR_USERNAME + password: YOUR_PASSWORD + folder: INBOX + search: FROM , SUBJECT + # Or use X-GM-RAW search-term like this, to find unread emails from the last 7 days in your inbox + # search: 'X-GM-RAW "in: inbox newer_than:7d is:unread"' + +# Example entry for Office 365 + + server: outlook.office365.com + port: 993 + username: email@address.com + password: password + search: FROM , SUBJECT + charset: US-ASCII ``` From b92c59e92a8b653f75fc24257c2d98f576532631 Mon Sep 17 00:00:00 2001 From: Rami Mosleh Date: Mon, 9 Jan 2023 13:42:05 +0200 Subject: [PATCH 2/2] Update imap.markdown --- source/_integrations/imap.markdown | 41 ++++++++++++------------------ 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/source/_integrations/imap.markdown b/source/_integrations/imap.markdown index 90174f46594d..bac642c00d39 100644 --- a/source/_integrations/imap.markdown +++ b/source/_integrations/imap.markdown @@ -14,20 +14,23 @@ ha_codeowners: ha_config_flow: true --- -The `imap` integration is observing your [IMAP server](https://en.wikipedia.org/wiki/Internet_Message_Access_Protocol) and reporting the amount of unread emails. Other search criteria can be used as shown in the example below. +The IMAP integration is observing your [IMAP server](https://en.wikipedia.org/wiki/Internet_Message_Access_Protocol) and reporting the number of unread emails. Other search criteria can be used, as shown in the example below. {% include integrations/config_flow.md %} ### Gmail with App Password -If you’re going to use Gmail, you need to create a [App Password](https://support.google.com/mail/answer/185833). +If you’re going to use Gmail, you need to create an [App Password](https://support.google.com/mail/answer/185833). 1. Go to your [Google Account](https://myaccount.google.com/) 2. Select **Security** 3. Under “Signing in to Google” select **App Passwords** 4. Sign in to your Account, and create a new App Password for Gmail. - -You can now use this as your password for Gmail, in your configuration. +5. Then you can setup the intergation as below: + - Server: `imap.gmail.com` + - Port: `993` + - Username: Your full email address + - Password: The new app password ### Configuring IMAP Searches @@ -37,24 +40,12 @@ By default, this integration will count unread emails. By configuring the search * `FROM`, `TO`, `SUBJECT` to find emails in a folder (see [IMAP RFC for all standard options](https://tools.ietf.org/html/rfc3501#section-6.4.4)) * [Gmail's IMAP extensions](https://developers.google.com/gmail/imap/imap-extensions) allow raw Gmail searches, like `X-GM-RAW "in: inbox older_than:7d"` to show emails older than one week in your inbox. Note that raw Gmail searches will ignore your folder configuration and search all emails in your account! -#### Config entry sample with search examples - -``` - server: imap.gmail.com - port: 993 - username: YOUR_USERNAME - password: YOUR_PASSWORD - folder: INBOX - search: FROM , SUBJECT - # Or use X-GM-RAW search-term like this, to find unread emails from the last 7 days in your inbox - # search: 'X-GM-RAW "in: inbox newer_than:7d is:unread"' - -# Example entry for Office 365 - - server: outlook.office365.com - port: 993 - username: email@address.com - password: password - search: FROM , SUBJECT - charset: US-ASCII -``` +### Selecting a charset supported by the imap server + +Below is an example for setting up the integration to connect to your Microsoft 365 account that requires `US_ASCII` as charset: + - Server: `outlook.office365.com` + - Port: `993` + - Username: Your full email address + - Password: Your password + - Charset: `US-ASCII` +