Imap_email_content don't create any entity

Hi.

I try to get some Information from my Gmail, and I found the imap_email_content integration.

This is my config:

sensor:
  - platform: imap_email_content
    server: imap.gmail.com
    name: crashplan_backup_status_report
    port: 993
    username: flemmingss
    password: !secret flemmingss_google_password
    senders:
      - [email protected]

When I first tried I got this one:

Logger: homeassistant.components.imap_email_content.sensor
Source: components/imap_email_content/sensor.py:95
Integration: imap_email_content (documentation, issues)
First occurred: November 24, 2021, 13:12:56 (1 occurrences)
Last logged: November 24, 2021, 13:12:56

Failed to login to imap.gmail.com

And I got this, and accepted/allowed it:

But I don’t find any new related entities in my Home-Assistant, I have tried to restart multiple times.

What do I do from here?

You have probably only just disposed the security warning and not really configured Gmail to allow the access from the lesser secure device.
I know that threw me off when I tried to get an app to connect to a Gmail account.

It a while ago, so I can not remember where it in Gmail I had to configure it, so you will have to hunt for insecure connection to Gmail accounts.

Hi, as of March 2023 i have the same issue about the sensor creation. I am running
Home Assistant 2023.3.1; Supervisor 2023.03.1; Operating System 9.5

My configuration is

sensor:
  - platform: imap_email_content
    name: "in-mail"
    server: imap.gmail.com
    port: 993
    username: !secret GmailUsername
    password: !secret GmailPassword
    folder: INBOX
    senders:
      - [email protected]

Note that in 2022 I only updated (core 2022.mm.0) updates, assuming the updates being cumulatives.
I did read about previous issues about imap_email_content, did I miss any update?

Also there is no errors or warnings generated in the log.

I have created a Google API key and using it for mail notification which is working fine…

This is not a HA issue.
This is an issue with Google not allowing access from applications it thinks are insecure by default.
You need to configure the Google account to allow access from the HA integration.

Mine stopped working as well. This happened about the same the I’ve updated to 2023.1.

  - platform: imap_email_content
    server: imap.mail.yahoo.com
    name: work
    port: 993
    username: !secret recipient_3
    password: !secret recipient_3_pass
    folder: External
    senders:
     - [email protected]
    value_template: >-
      <some info goes here>

I have the same problem with gmail. I am using an app password. I am sure the user / password combination is working, since it is working with get-mail. But in HA i get the following error in the logs:



Logger: homeassistant.components.sensor
Source: components/imap_email_content/sensor.py:105
Integration: Sensor (documentation, issues)
First occurred: 2:49:51 PM (1 occurrences)
Last logged: 2:49:51 PM
Error while setting up imap_email_content platform for sensor

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 293, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/imap_email_content/sensor.py", line 74, in setup_platform
    sensor = EmailContentSensor(
  File "/usr/src/homeassistant/homeassistant/components/imap_email_content/sensor.py", line 175, in __init__
    self.connected = self._email_reader.connect()
  File "/usr/src/homeassistant/homeassistant/components/imap_email_content/sensor.py", line 105, in connect
    self.connection = imaplib.IMAP4_SSL(
  File "/usr/local/lib/python3.10/imaplib.py", line 1323, in __init__
    IMAP4.__init__(self, host, port, timeout)
  File "/usr/local/lib/python3.10/imaplib.py", line 202, in __init__
    self.open(host, port, timeout)
  File "/usr/local/lib/python3.10/imaplib.py", line 1336, in open
    IMAP4.open(self, host, port, timeout)
  File "/usr/local/lib/python3.10/imaplib.py", line 312, in open
    self.sock = self._create_socket(timeout)
  File "/usr/local/lib/python3.10/imaplib.py", line 1326, in _create_socket
    sock = IMAP4._create_socket(self, timeout)
  File "/usr/local/lib/python3.10/imaplib.py", line 302, in _create_socket
    return socket.create_connection(address)
  File "/usr/local/lib/python3.10/socket.py", line 824, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/local/lib/python3.10/socket.py", line 955, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name does not resolve





does anyone have the same problem? What can I do to solve it?

Update Solution:

It seems the problem was that I did not set a folder. According to the documentation it is not needed and the default is INBOX. But in reality I had to set the folder. And be careful not to have any spaces after the folder name.

This might be a DNS resolution issue.
Check that your DNS is setup correctly by running “ha info resolution” on the HA installation.
Remember that if IPv6 is enabled then it should work too, because Google have IPv6 enabled and then it will be first priority to use that protocol.

2023.3.6 addresses the imap_email_content issue. Will see if it works as before.