r/PythonLearning • u/PotentialMain535 • Jul 08 '26
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!

4
Upvotes
1
u/Electrical_Toe8997 Jul 09 '26 edited Jul 09 '26
Looks pretty good and if it works, that's great!
I have a few points:
The send_email function does not actually send emails. Rename to create_email.
The email_check function: rename to check_email or (better) check_address. This makes it clearer what it does and aligns it with the other functions (check_file and send_email/create_email). Then, look into regular expressions to check whether an address is valid. The function you have now will return True for the value "a.@", which will not work.
You have two while loops to get the email data and attachment from the user. You could make these into functions (get_email_data and get_attachment). This would also make it easier to do the next item:
Add the option for the user to not add an attachment. Get input ('Attachment Y or N?') and get the attachment info based on the answer.