22: Send Yahoo! Email using smtplib - SMTP protocol client using Python Program

In this program, we take a look at how to send an Email using your Yahoo! Email using the Python SMTP library.

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

# Email configuration
smtp_yahoo_server = 'smtp.mail.yahoo.com'
smtp_yahoo_port = 587
sender_email = 'your_yahoo_email@yahoo.com'
sender_password = 'your_yahoo_mail_password'
receiver_email = 'recipient@example.com'
email_subject = 'Email Using Python Code'
email_body = 'Hello, this is an email body test!'

# Multipart message
multipart_msg = MIMEMultipart()
multipart_msg['From'] = sender_email
multipart_msg['To'] = receiver_email
multipart_msg['Subject'] = email_body

# Sending email
multipart_msg.attach(MIMEText(multipart_msg, 'plain'))
smtp = smtplib.SMTP(smtp_yahoo_server, smtp_yahoo_port)
smtp.login(sender_email, sender_password)
smtp.sendmail(sender_email, receiver_email, multipart_msg.as_string())

Read More: smtplib — SMTP protocol client


Facing issues? Have Questions? Post them here! I am happy to answer!

Author: Rakesh
Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

Copyright © Code2care 2023 | Privacy Policy | About Us | Contact Us | Sitemap