首页 > 编程语言 > 详细

python 发邮件

时间:2014-09-04 14:50:09      阅读:243      评论:0      收藏:0      [点我收藏+]

简单实现

用了2个模块, smtplib 主要的三个函数login ,sendmial ,close

SMTP.login(userpassword)

SMTP.sendmail(from_addrto_addrsmsg[, mail_optionsrcpt_options])

https://docs.python.org/2/library/smtplib.html#smtp-example

#!/usr/bin/python
#coding:utf-8
import smtplib
from email.mime.text import MIMEText
user=‘22@qq.com‘ passwd=‘xxx‘
to=‘xxx@qq.com‘

msg=MIMEText("早上好")

msg["Subject"] = 	‘hi,man‘
msg[‘From‘]	=	user
msg[‘to‘]	=	to
print msg.as_string()
s=smtplib.SMTP(‘smtp.qq.com‘)
s.login(user,passwd)
s.sendmail(user,to,msg.as_string())
s.close()

  

发中文,必须在之前加入  #coding:utf-8 ,否则会报错。

 

python 发邮件

原文:http://www.cnblogs.com/gqdw/p/3955962.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!