Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending e-mails using yahoo account in python

Tags:

python

email

smtp

I have yahoo account. Is there any python code to send email from my account ?

like image 402
user2351194 Avatar asked May 05 '13 04:05

user2351194


People also ask

Can I use Yahoo as SMTP server?

Yahoo.com supports IMAP / SMTP This means you don't have to use Yahoo.com's webmail interface! You can check your email and send messages using other email programs (like Mailspring, Outlook Express, Apple Mail, or Mozilla Thunderbird).

How do I send an email using Python?

Use Python's built-in smtplib library to send basic emails. Send emails with HTML content and attachments using the email package. Send multiple personalized emails using a CSV file with contact data. Use the Yagmail package to send email through your Gmail account using only a few lines of code.

Can Python be used to send emails?

Python offers a ` library to send emails- “SMTP lib”. “smtplib” creates a Simple Mail Transfer Protocol client session object which is used to send emails to any valid email id on the internet.

How do I send an email in Python 2022?

Below you can find an example of a simple Python script that shows how one can send an email from a local SMTP. import smtplib sender = '[email protected]' receivers = ['[email protected]'] message = """From: From Person <[email protected]> To: To Person <[email protected]> Subject: SMTP email example This is a test message.


1 Answers

I racked my head (briefly) regarding using yahoo's smtp server. 465 just would not work. I decided to go the TLS route over port 587 and I was able to authenticate and send email.

import smtplib
from email.mime.text import MIMEText
SMTP_SERVER = "smtp.mail.yahoo.com"
SMTP_PORT = 587
SMTP_USERNAME = "username"
SMTP_PASSWORD = "password"
EMAIL_FROM = "[email protected]"
EMAIL_TO = "[email protected]"
EMAIL_SUBJECT = "REMINDER:"
co_msg = """
Hello, [username]! Just wanted to send a friendly appointment
reminder for your appointment:
[Company]
Where: [companyAddress]
Time: [appointmentTime]
Company URL: [companyUrl]
Change appointment?? Add Service??
change notification preference (text msg/email)
"""
def send_email():
    msg = MIMEText(co_msg)
    msg['Subject'] = EMAIL_SUBJECT + "Company - Service at appointmentTime"
    msg['From'] = EMAIL_FROM 
    msg['To'] = EMAIL_TO
    debuglevel = True
    mail = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
    mail.set_debuglevel(debuglevel)
    mail.starttls()
    mail.login(SMTP_USERNAME, SMTP_PASSWORD)
    mail.sendmail(EMAIL_FROM, EMAIL_TO, msg.as_string())
    mail.quit()

if __name__=='__main__':
send_email()
like image 184
xpros Avatar answered Oct 04 '22 15:10

xpros