This quick article describes using Gmail as your e-mail server to send e-mail via Python's built-in SMTP library. It's not complicated, I promise.
Here's how to sign in to Gmail in Python:
Import Smtplib # The below code never changes, though obviously those variables need values.session = Smtplib. SMTP (' smtp.gmail.com ', 587) Session.ehlo () Session.starttls () Session.login (Gmail_username, Gmail_password)
Here's how to send a message in Python:
headers = "\ r \ n". Join (["From:" + Gmail_username, "Subject:" + Email_subject "to:" + recipient, "Mime-versi on:1.0 ", " content-type:text/html "]) # Body_of_email can be plaintext or html! Content = headers + "\r\n\r\n" + body_of_emailsession.sendmail (gmail_username, recipient, content)
Depending on your mastery of Python, this can be a fairly small or quite long code.
For me, the first time I took a program to send an email, as I saw the scene in The matrix, it was like the first time I built a website on Godaddy, or as I first used Joptionpane's doubts. This is an implementation method (a simple method that makes implementing a similar application very simple), although I've seen a lot of e-mail code before, but it still leaves a deep impression on me.
And, despite the simplicity of the code above, I spent the first time trying my best to write the code out for two hours. So I hope to help some other people.