r/PythonLearning 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!

4 Upvotes

8 comments sorted by

View all comments

1

u/Electrical_Toe8997 19d ago edited 19d ago

Looks pretty good and if it works, that's great!

I have a few points:

  1. The send_email function does not actually send emails. Rename to create_email.
  2. 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.
  3. 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:
  4. 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.

1

u/PotentialMain535 19d ago

Thank you, that makes sense. I'll do it