It's time for another project.
And this time we're going to use Python to send emails.
That's right.
We can send emails with Python.
Now we'll explore why this might be useful later on.
But I want to give you a heads up.
Python has a built in email module and this module actually got updated with Python 3.6.
So I'm going to show you the latest version.
When you Google how to send emails with Python, you might see a lot of outdated ways to send emails.
So just a heads up that you might see something different than what I'm about to show you.
But as of recording this video, this is the latest way to send emails.
So why might this be useful?
Well, imagine you have a list of emails that you've collected and you want to launch a new startup.
You want people to know about your startup, right?
So we can create a program that sends emails to maybe hundreds, thousands of people at the same time,
maybe a customized email with their name to promote our product.
Now we'll get into spamming and things like that later on.
But you might be thinking to yourself, why do we need Python for this?
For example, there are tools like.
MailChimp.
That is a software subscription based product that allows us to do this.
We can collect emails and also send customized emails.
And you're right, companies like MailChimp or Miller Lite or there's hundreds of them allow us to send
lots of emails to potential customers to sell leads in order to try and grow our business.
But I want to show you how to do with Python, because there are times that it might come in useful.
So let's get to it.
And I'm going to use this project as an occasion for us to learn a few built in packages in Python.
Now the first one we're going to use is the SMTP lib.
So Asim tpy lib module.
And we're also going to say from email dot messages, import email.
Message.
And this should be email message.
Again, this is the email module that comes built in to Python.
And actually I'll link over here where it shows you some of the legacy API.
So that is the outdated way to use things.
We're going to do the email stored messages way of sending emails.
Now.
The other one is SMTP.
Now, SMTP is going to allow us to create what we call an SMTP server.
Any time you send emails to anybody, it needs to have a server that communicates the language of the
email.
And this is what SMTP is used for.
For example, on websites, you might see HTTP or https as the protocol of communication between a browser
and a server in the same way e mails have their own protocol for communicating, and that's through
SMTP.
As a matter of fact, the acronym stands for Simple Mail Transfer Protocol.
It's a protocol or a standard for emails to be sent from computer to computer.
Gmail uses this, Hotmail uses this pretty much most email clients.
I'm going to link to some resource if you want to read more about SMTP.
But the key thing is, if we want to send an email, we need SMTP server.
Now from here, we're going to dive into how to send our first email.
Before we get into that and the next video, I want you to go ahead and create an email account.
If you don't have one, I'm going to use a dummy email account, a Gmail account that I just created,
because what we're going to do is we're going to have to log into this using a password, our username,
and actually send an email from this email account without actually using this browser.
So go ahead and create a dummy Gmail account or you can use your regular one if you want.
But I like to keep my passwords just away from everything, and I don't really want to share my personal
email password with you, so I'm going to use this one.
All right.
Let's take a break and send our first email in the next video.