Send Email to Yahoo

Cross Platform
Admin
Site Admin
Posts: 951
Joined: Thu Aug 23, 2007 10:35 am

Send Email to Yahoo

Postby Admin » Sun Jul 08, 2012 6:01 pm

Code: Select all

# settings

SMTP_SERVER = 'mta5.am0.yahoodns.net'
SMTP_PORT = 25
SMTP_USERNAME = 'myusername'
SMTP_PASSWORD = '$uper$ecret'
SMTP_FROM = 'dave@hotmail.com'
SMTP_TO = 'smithj355@yahoo.com'

TEXT_FILENAME = '/script/output/my_attachment.txt'
MESSAGE = """This is the message
to be sent to the client.
"""

# now construct the message
import smtplib, email
from email import encoders
import os

msg = email.MIMEMultipart.MIMEMultipart()
body = email.MIMEText.MIMEText(MESSAGE)
attachment = email.MIMEBase.MIMEBase('text', 'plain')
attachment.set_payload(open(TEXT_FILENAME).read())
attachment.add_header('Content-Disposition', 'attachment', filename=os.path.basename(TEXT_FILENAME))
encoders.encode_base64(attachment)
msg.attach(body)
msg.attach(attachment)
msg.add_header('From', SMTP_FROM)
msg.add_header('To', SMTP_TO)

# now send the message
mailer = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
mailer.connect()
#mailer.login(SMTP_USERNAME, SMTP_PASSWORD)
mailer.sendmail(SMTP_FROM, [SMTP_TO], msg.as_string())
mailer.close()

Return to “Python”

Who is online

Users browsing this forum: No registered users and 1 guest