Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion airflow/providers/imap/hooks/imap.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def get_conn(self) -> 'ImapHook':
"""
if not self.mail_client:
conn = self.get_connection(self.imap_conn_id)
self.mail_client = imaplib.IMAP4_SSL(conn.host)
self.mail_client = imaplib.IMAP4_SSL(conn.host, conn.port or imaplib.IMAP4_SSL_PORT)
self.mail_client.login(conn.login, conn.password)

return self
Expand Down
7 changes: 5 additions & 2 deletions docs/apache-airflow-providers-imap/connections/imap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ Password
Specify the password used for the IMAP client.

Host
Specify the the IMAP host url.
Specify the IMAP host url.

Port
Specify the IMAP port to connect to.

When specifying the connection in environment variable you should specify
it using URI syntax.
Expand All @@ -57,4 +60,4 @@ For example:

.. code-block:: bash

export AIRFLOW_CONN_IMAP_DEFAULT='imap://username:password@myimap.com'
export AIRFLOW_CONN_IMAP_DEFAULT='imap://username:password@myimap.com:993'
3 changes: 2 additions & 1 deletion tests/providers/imap/hooks/test_imap.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def setUp(self):
conn_type='imap',
host='imap_server_address',
login='imap_user',
port=1993,
password='imap_password',
)
)
Expand All @@ -74,7 +75,7 @@ def test_connect_and_disconnect(self, mock_imaplib):
with ImapHook():
pass

mock_imaplib.IMAP4_SSL.assert_called_once_with('imap_server_address')
mock_imaplib.IMAP4_SSL.assert_called_once_with('imap_server_address', 1993)
mock_conn.login.assert_called_once_with('imap_user', 'imap_password')
assert mock_conn.logout.call_count == 1

Expand Down