首页 > 编程语言 > 详细

python实现发送邮件

时间:2015-10-25 13:39:16      阅读:217      评论:0      收藏:0      [点我收藏+]

下面的程序利用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()

 

python实现发送邮件

原文:http://www.cnblogs.com/wuyouwulv/p/python_send_email.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!