I have yahoo
account.
Is there any python code to send email from my account ?
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).
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.
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.
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.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With