首页 » Code » Python » python-发送邮件-源码

python-发送邮件-源码

 
#coding: utf-8
import smtplib
import sys
from email.mime.text import MIMEText
from email.header import Header
def sendmail(username,password,receiver,subject,text):
  sender = username
  smtp = smtplib.SMTP()
  smtp.connect('smtp.126.com')
  smtp.login(username, password)
  msg = MIMEText(text,'plain','utf-8')#中文需参数‘utf-8’,单字节字符不需要
  msg['Subject'] = Header(subject, 'utf-8')
  msg['From'] = '名称<ituser@126.com>' #在收件箱列表显示:名称
  for peple in receiver:
  smtp.sendmail(sender, peple, msg.as_string())
  smtp.quit()
if __name__ == '__main__':
  argv = sys.argv
  sender = 'ituser@126.com'  #发件人
  receiver = ('#########','########') #收件人
  subject = '########'  #邮件标题
  text = '内容'
  username = 'ituser@126.com'  #邮箱账号
  password = '*****'  #邮箱授权码
  sendmail(username,password,receiver,subject,text)

 

–ituse.cn-小小IT人遨游大大IT界

原文链接:python-发送邮件-源码,转载请注明来源!

0