After learning how to establish a secure connection to a SMTP server, it’s time to send an actual email! Therefore, this video shows you how to create an email and send it via Python to another mail account using built-in functionalities.
Sending Plaintext Emails With Python
Now that you know how to create secure connections to a mail server, it’s time to send an actual email. We’re going to change this code to create the encrypted connection from the start, so the first thing you need to do is change this
port back to
465, and then go ahead and delete all these
except blocks here.
And once you’re logged in, here is where you would actually send the email. At this point, you need to add a couple more parameters. You need to know who you’re sending the email to, so you can just do something like
02:41 There’s the email from my other email account. If you don’t see it in your inbox, try refreshing. I’d say about 50/50 of the time they’ll end up in my spam, so don’t get too frustrated if you don’t see it there. Now, there is one thing to note with this email. If you click on to, you can see you’ve got your TLS encryption here, but it’s from the other email account, but it actually wasn’t sent to this email account.
03:09 So, if we go back to the email account that sent the email and head to Sent—okay, here it is. Let’s open this up. And if you look, the receiver email was actually blind carbon copied on here and it wasn’t sent directly to them.
03:28 If you want to send an email directly to somebody, you have to make a couple changes to the message itself. This is due to the SMTP protocol. If you’re familiar with HTTP requests, you may realize that there are a series of lines where each line means something.
04:13 We don’t see any errors, so hop over to the inboxes. Now if I go back to Sent, you can see that this time it was actually sent to that email. And in the actual inbox, here’s the second one, and it was sent to the email.
04:35 So, the formatting of your message can play into how it’s actually sent, so if you’re running into issues don’t be afraid to look around and see if the SMTP protocol is playing into how your messages are going out. All right!
Become a Member to join the conversation.