As already stated, you need:
- SMTP server for sending emails
- IMAP for reading emails
- POP3 for reading emails
IMAP is more powerful than POP3; in general, you probably want to use IMAP. POP3 deletes the emails after they have been read, unlike IMAP.
For SMTP you can use Python's smtplib, for IMAP you can use imaplib and for POP3 you can use poplib (all from standard library). However, they are all pretty low-level.
I have created more abstract alternatives to make things easy for everyone:
Here is an example of Red Mail:
from redmail import EmailSender
# Configure sender
email = EmailSender(host="smtp.example.com", port=587)
# Send an email
email.send(
subject="An example email",
sender="me@example.com",
receivers=['you@example.com'],
text="Hello!",
html="<h1>Hello!</h1>"
)
And an example of Red Box:
from redbox import EmailBox
from redbox.query import UNSEEN, SUBJECT
# Configure email box
box = EmailBox(host="imap.example.com", port=993)
# Select email folder
inbox = box['INBOX']
for msg in inbox.search(UNSEEN & SUBJECT("An example email")):
# Process the message
print(msg.subject)
print(msg.from_)
# Mark the message as read
msg.read()
You can pip install the libraries:
pip install redmail redbox
Relevant links
Red Box:
Red Mail: