#!/usr/bin/python import smtplib from email.Message import Message from time import sleep smtpserver='smtp.gmail.com' username='hzhida95@gmail.com' password='*******' from_addr='hzhida95@gmail.com' to_addr='hzhida2011@gmail.com' cc_addr='1241224798@qq.com' message=Message() message['Subject']='Mail Subject' message['From']=from_addr message['To']=to_addr message['Cc']=cc_addr message.set_payload('mail content') msg=message.as_string() sm=smtplib.SMTP(smtpserver,port=587,timeout=20) sm.set_debuglevel(1) sm.ehlo() sm.starttls() sm.ehlo() sm.login(username,password) sm.sendmail(from_addr,to_addr,msg) sleep(5) sm.quit()