How to send email using python

Free Python Code - Aug 14 '23 - - Dev Community

welcome everybody 🙂🖐

Today I will share with you How to send email using python

step 1

you need to choice Mail Service Provider
like yahoo, gmail, aol
this is list of 10 Best FREE Email Account: Mail Service Providers (2023 List)

choice one of them 🤗

step 2

In this step you need to go to your account
To generate an application password or set the settings according to the service
if you useing aol or yahoo you will make the Same settings
Because they are similar to each other

Go to your account
Then select "security".

Image description

Scroll down the page
Even the "ACCOUNT ACCESS" section
"

Click on Generate app password
Image description

Click Get started

Image description

Choose the name of the application

Image description

Copy the password

Image description

step 3

you need to kenow 2 things 1 - SMTP server name 2 - SMTP server port of your Mail Service Provider
for example aol

AOL SMTP server name: smtp.aol.com
AOL SMTP username: your AOL address
AOL SMTP password: your account password
AOL SMTP port: 25 or 465

Note!
i used port : 587 instead of 465 Because port 465 is not working

The same idea on all Mail Service Provider's
Use Google to find this info or use Google bard

step 4

you need an email to receive the message
you can use temp-mail

step 5


import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

msg = MIMEMultipart()
msg['From'] = 'your email'
msg['To'] = 'receiver email'
msg['Subject'] = 'Test ;)'


html = """ 

<h1>Hi, This is test 🙂</h1>

"""

msg.attach(MIMEText(html, 'html'))
msg_str = msg.as_string()


server = smtplib.SMTP('smtp.aol.com', 587)

server.starttls()
server.ehlo()


server.login('email username', 'your password')
server.send_message(msg)

Enter fullscreen mode Exit fullscreen mode

Image description

Now we're done 🤗

Don't forget to like and follow 🙂

Support me on PayPal 🤗
https://www.paypal.com/paypalme/amr396

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .