Last active
March 3, 2023 17:32
-
-
Save girorme/da332d40f5bdd7f45939cee83e1eec9c to your computer and use it in GitHub Desktop.
Read emails imap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule ImapExample do | |
def mark_unread_emails_as_read(server, username, password) do | |
{:ok, conn} = ExImap.connect(server: server, ssl: true) | |
{:ok, _} = ExImap.authenticate(conn, username: username, password: password) | |
{:ok, _} = ExImap.select(conn, "INBOX") | |
{:ok, messages} = ExImap.search(conn, "UNSEEN") | |
Enum.each(messages, fn msg_id -> | |
{:ok, _} = ExImap.store(conn, msg_id, "+FLAGS", "\\Seen") | |
end) | |
:ok = ExImap.quit(conn) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# read mails with python using imap | |
import imaplib | |
# Connect to the IMAP server | |
imap_server = imaplib.IMAP4_SSL('imap.gmail.com') | |
imap_server.login('[email protected]', 'your_password') | |
imap_server.select() | |
# Search for unread emails | |
status, messages = imap_server.search(None, 'UNSEEN') | |
# Mark each unread email as read | |
for msg_id in messages[0].split(): | |
imap_server.store(msg_id, '+FLAGS', '\\Seen') | |
# Close the connection | |
imap_server.close() | |
imap_server.logout() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment