python 发送邮件小程序,python smtplib模块发邮件

发布时间:2020-05-23编辑:脚本学堂
一个python 发送邮件的小程序,用到了python smtplib模块与string模块,smtp方式发送邮件的例子。

python代码:   
 

复制代码 代码示例:

#!/usr/bin/env python
#_*_encoding:utf-8_*_
import smtplib
import string

FROM = raw_input("请输入邮箱地址:")
FROM_PASS = raw_input("请输入邮箱密码:")
HOST = raw_input("请输入邮箱SMTP服务器地址(例如:smtp.qq.com:):")
TO = raw_input("请输入对方邮箱地址:")
SUBJECT = "Mail"
text = "This is a test mail !"
BODY = string.join((
        "FROM: %s" % FROM,
        "TO: %s" % TO,
        "Suject: %s" % SUBJECT,
        "",
        text
        ),"rn")
server = smtplib.SMTP()
server.connect(HOST,"25")
server.login(FROM,FROM_PASS)
server.sendmail(FROM,[TO],BODY)
server.quit()