Python 发送邮件 smtplib

巴扎黑
发布: 2016-12-09 11:25:17
原创
950 人浏览过

可以利用smtplib模块来实现发送邮件的功能,一个比较简单的实例代码如下:

# Import smtplib for the actual sending function
import smtplib
# Import the email modules we'll need
from email.mime.text import MIMEText
# Open a plain text file for reading. For this example, assume that
# the text file contains only ASCII characters.
# Create a text/plain message
msg = MIMEText("some content")
me = you = 'somebody@somewhere.com'
# me == the sender's email address
# you == the recipient's email address
msg['Subject'] = 'The contents of somebody'
msg['From'] = me
msg['To'] = you
# Send the message via our own SMTP server, but don't include the
# envelope header.
s = smtplib.SMTP('localhost')
s.sendmail(me, [you], msg.as_string())
s.quit()
登录后复制



相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!