Sending Emails in Python

From Knowledge Center
Jump to: navigation, search
import csv
import smtplib

INTRO_MSG = """
Hi {recipient},

Congratulations! You have made the team.

Your coach {coach},
Thanks
"""

smtp = smtplib.SMTP('smtp.host.com')
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
smtp.login('me@mydomain.com', 'sekretpass')

msg = ACCEPTED_MSG.format(recipient='James', coach='Frank')
smtp.sendmail('me@mydomain.com', 'james@domain.com', msg)
smtp.close()