Use Python to log on to Gmail and send a Gmail mail tutorial, pythongmail
This article describes how to use Gmail as your e-mail server to send emails through the built-in SMTP library of Python. It is not complicated, I promise.
The following describes how to log on 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)
The following describes how to send emails in Python:
headers = "\r\n".join(["from: " + GMAIL_USERNAME, "subject: " + email_subject "to: " + recipient, "mime-version: 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 understanding of Python, this may be a fairly small or quite long piece of code.
For me, the first time I used a program to send an email, just like the moment I saw the scenario in the matrix, just like the first time I set up a website on Godaddy, or, for the first time I used JOptionPane. This is an implementation method (a simple method that makes it very simple to implement similar applications), although I have read a lot of mail code before, however, this still leaves a deep impression on me.
In addition, despite the simplicity of the above code, I did my best for the first time. It took more than two hours to write those codes. So I want to help others.