I am the author for two libraries that could solve the problem:
First we configure Red Mail and Red Box:
from redbox import EmailBox
from redmail import EmailSender
USERNAME = "me@example.com"
PASSWORD = "<PASSWORD>"
box = EmailBox(
    host="imap.example.com", 
    port=993,
    username=USERNAME,
    password=PASSWORD
)
sender = EmailSender(
    host="smtp.example.com", 
    port=587,
    username=USERNAME,
    password=PASSWORD
)
Then we read the email box with Red Box:
from redbox.query import UNSEEN
# Select an email folder
inbox = box["INBOX"]
# Search and process messages
for msg in inbox.search(UNSEEN):
    # Set the message as read/seen
    msg.read()
    
    # Get attribute of the message
    sender = msg.from_
    subject = msg.subject
Lastly we send an email with Red Mail:
sender.send(
    subject='You sent a message',
    receivers=[sender],
    text=f"Hi, you sent this: '{subject}'.",
)
Install the libraries
pip install redbox redmail
Links:
Red Box
Red Mail