This quick article introduces the use of Gmail as your e-mail server, through Python's built-in SMTP library to send e-mail. It's not complicated, I promise.
Here's how to log in to Gmail in Python:
Import smtplib
# below code never changes, though obviously those variables 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-vers ion:1.0 ",
" content-type:text/html "])
# body_of_email can be plaintext or html!
Content = headers + "\r\n\r\n" + body_of_email
session.sendmail (gmail_username, recipient, content)
Depending on your mastery of Python, this could be a fairly small or fairly long code.
For me, the first time I took a program to send an email, as I saw the scene in The matrix, like the first time I built a website on a Godaddy, or the first time I used a joptionpane puzzle. This is an implementation approach (a simple way to make a similar application very simple), although I've seen a lot of email code before, but it still impresses me.
In addition, although the above code is simple, but the first time I did my best, it took two hours to write the code. So I hope I can help some other people.