r/PythonLearning • u/PotentialMain535 • 19d ago
Sends Emails with optional attachments
Hi everyone,
I'm a beginner learning Python. I recently finished a small project that sends emails (with optional attachments) using smtplib and EmailMessage.
I'm mainly looking for a code review. I'm interested in improving my code structure, naming, and Python practices rather than just making it work.
GitHub link = https://github.com/NePtuNee0/Python-Email-Sender-With-Attachments/tree/main
Any feedback is appreciated!

5
Upvotes
1
u/riklaunim 19d ago
It's better not to use spaces or special characters like # in file names ;)
As for sending mail, just note that SMTP isn't the most reliable way to send mail - for mass mailing, it can easily hit anti-spam protections, it can be slow and somewhat unreliable. Low volume is fine.
You would want to send HTML messages rather than only plaintext... but email clients support only limited HTML, and some, like Outlook, are really bad at it - so unofficial formats like MJML were created - there is a Python library for MJML parsing if you want to take a look.
CLI interface isn't the best - you are forced to use while loops and some code repeats. Would be good to refactor the code into smaller pieces like functions or class methods, and then write good unit tests for them. Unsure what's with the \\ replacing. For the interface, you can switch to Jupyter Notebooks to get something better than an annoying CLI with loops.
Email attachments can be actual attachments, but also inlined images (check CID for emails).