Screen Shot 2021-09-25 at 2.59.23 AM.png

So in Python, there's a module called SMTP lib

which allows us to use SMTP to send our email to any address on the internet.

SMTP Information

Screen Shot 2021-09-25 at 2.46.48 PM.png

starttls(): TLS stands for transport layer security, and it's a way of securing our connection to all email server.

import smtplib

my_email = "[email protected]"
password = "XXXX"

connection = smtplib.SMTP("smtp.gmail.com")
connection.starttls()
connection.login(user=my_email, password=password)
connection.sendmail(
    from_addr=my_email,
    to_addrs="[email protected]",
    msg="Subject:Hello\\n\\nThis is the body of my email."
)

connection.close()
import smtplib

my_email = "[email protected]"
password = "XXXX"

with smtplib.SMTP("smtp.gmail.com") as connection:
    connection.starttls()
    connection.login(user=my_email, password=password)
    connection.sendmail(
        from_addr=my_email,
        to_addrs="[email protected]",
        msg="Subject:Hello\\n\\nThis is the body of my email."
    )