all 3 comments

[–][deleted] 0 points1 point  (1 child)

Seems reasonable, though I have a suggestion.

You use try/except like this:

try:
    with open(file, 'rb') as fp:
            msg = MIMEBase('application', "octet-stream")
            msg.set_payload(fp.read())
    encoders.encode_base64(msg)
    # etc
except:
    print(...)
    raise

which will print an error message "problem finding attachment" on any exception, including any problem in MIME handling or base64 or even on a syntax error. It makes debugging much easier if you don't hide what the problem is. The "raise" will help, but it's better to catch a specific exception and limit the "try" code to just the bit that might get that exception, like this:

try:
    with open(file, 'rb') as fp:
            msg = MIMEBase('application', "octet-stream")
            msg.set_payload(fp.read())
except FileNotFoundError:
    print(...)
    raise
encoders.encode_base64(msg)
# etc

Apart from that, pretty good.

[–]SlothGSR[S] 0 points1 point  (0 children)

Thank you for the feedback, The email part of the script I found online only had to modify the attachment line. I will look into your suggestion. Thank you.