Skip to content

Instantly share code, notes, and snippets.

@girorme
Last active March 3, 2023 17:32
Show Gist options
  • Save girorme/da332d40f5bdd7f45939cee83e1eec9c to your computer and use it in GitHub Desktop.
Save girorme/da332d40f5bdd7f45939cee83e1eec9c to your computer and use it in GitHub Desktop.
Read emails imap
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
# 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