Here is a code to confirm mail sending configuration in Python.
Environment
- Python 3.10
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import smtplib if __name__ == "__main__": fromaddr = 'from-addr@email.com' toaddrs = [ 'recipient1@email.com', 'recipient2@email.com', 'recipient3@email.com' ] # Add the From: and To: headers at the start! msg = ("From: %s\r\nTo: %s\r\n\r\n" % (fromaddr, ", ".join(toaddrs))) text = """ This is a test message. """ msg += text print("Message length is", len(msg)) server = smtplib.SMTP('smtp-server.email.com', 587) res = server.login( 'login-mail@email.com', 'XXX_PASSWORD_XXX' ) print(res) server.set_debuglevel(1) server.sendmail(fromaddr, toaddrs, msg) server.quit() |
Python smtplib standard module helps to communicate with SMTP server and send email easily. The above code sends email via SMTP and we can check SMTP configuration with it.