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 Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright ยฉ Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap