smtplib模块
smtplib.SMTP([host[, port[, local_hostname[, timeout]]]])
SMTP.connect([host[,port]])远程主机
SMTP.login(user.password)远程校验
SMTP.sendmail(from_addr,to_addrs,msg[,mail_options,rcpt_options])实现邮件的发送功能
SMTP.stattls([keyfile[,certfile]])启动TLS安全传输模式
SMTP.quit()断开SMTP服务器连接
#!/usr/bin/env python
import smtplib
import string
HOST = "smtp.163.com"
SUBJECT = "Test email from Python"
TO = "[email protected]"
FROM = "[email protected]"
text = "Python rules them all!"
BODY = string.join((
"From:%s" % FROM,
"TO:%s" % TO,
"Subject:%s" % SUBJECT,
"",
text
),"\r\n")
server = smtplib.SMTP()
server.connect(HOST,"25")
#server.starttls()
server.login("[email protected]","xxx")
server.sendmail(FROM,[TO],BODY)
server.quit()
时间: 2024-10-13 16:34:03