标签:
下面的程序利用smtp协议实线邮件的发送。接下来会优化使得也能够利用pop3或者imap协议实现邮件的收取。
#/usr/bin/env python #-*- coding:utf8 -*- import smtplib from email.mime.text import MIMEText class Mail_helper: def __init__(self): self.username = raw_input(‘username: ‘) self.password = raw_input(‘password: ‘) def send(self): host = ‘smtp.163.com‘ port = 25 receiver = raw_input(‘send to: ‘) title = raw_input(‘title: ‘) body = ‘<p>‘+raw_input(‘content: ‘)+‘</p>‘ msg = MIMEText(body, ‘html‘) msg[‘subject‘] = title msg[‘from‘] = self.username msg[‘to‘] = receiver s = smtplib.SMTP(host, port) s.login(self.username, self.password) s.sendmail(self.username, receiver, msg.as_string()) print ‘mail has been sent.‘ if __name__ == ‘__main__‘: mailer = Mail_helper() mailer.send()
标签:
原文地址:http://www.cnblogs.com/wuyouwulv/p/python_send_email.html