DEV Community

Anja
Anja

Posted on

How to send E-Mails with Python

Hey everyone! Today we have a look at another automation possibility with Python, this time we are using the smtplib module. SMTP stands for Simple Mail Transfer Protocol and is the protocol for sending emails. It determines how emails should be encrypted, formatted and relayed between mail servers.

In my code we only do a few simple steps to get started.
Alt Text

First we create a SMTP object for connecting to GMail. Next we use the method smtpObj.ehlo() to establish a connection to the server. We then set up TLS Encryption by calling smtpObj.starttls(). This is very important because otherwise anyone could fetch your password.

After this we login with the password, send an Email and at the end, disconnect from the server. For using googlemail, you need an extra step which is getting an app password. Read here how you can do this:

https://support.google.com/accounts/answer/185833

You will then get an extra password for your Python app which you use to login with SMTP instead of your normal password. Have a nice day!

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

πŸ‘‹ Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay