Python标准库中,发邮件程序一般要用到smtplib和email两个模块.
模块的具体功能还没有掌握清楚,不过照着写一个简单的邮件发送程序还是很简单的
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import smtplib
from email.mime.text import MIMEText
def sendmail(target, subject, content):
user = 'ontseason@163.com'
password = '****'
msg = MIMEText(content, 'html', 'utf-8')
msg['Subject'] = subject
msg['From'] = user
msg['To'] = target
s = smtplib.SMTP()
s.connect('smtp.163.com')
s.login(user, password)
s.sendmail(user, target, msg.as_string())
s.quit()
str = '<html><h2>你好啊</h2></html>'
if __name__ == '__main__':
sendmail('ontseason@163.com', 'Hello', str)