Python Sending Email Example

Do you like this?

Summary:
This short example shows you how to send emails through Python


Content:

import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText

your_email="your-email@gmail.com"
your_password="your-password"
to_email="target@gmail.com"

server= smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login(your_email, your_password)
msg=MIMEMultipart()
msg['From']=your_email
msg['To']=to_email
msg['Subject']="subject"
body= "a message"
msg.attach(MIMEText(body, 'plain'))
server.sendmail(your_email,to_email,msg.as_string()) #sending emails with subjects

server.sendmail(your_email,to_email,"plain message") #sending emails without subjects

 
comments powered by Disqus