首页 > 编程语言 > 详细

python3关于邮件的操作

时间:2019-05-06 11:46:40      阅读:153      评论:0      收藏:0      [点我收藏+]

话不多说,上代码

import smtplib
from email.mime.text import MIMEText   # 导入模块

class SendEmail:

    def send_emil(self, username, passwd, recv, title, content, mail_host=‘smtp.163.com‘, port=25):
        msg = MIMEText(content)      #邮件内容
        msg[‘Subject‘] = title
        msg[‘From‘] = username
        msg[‘To‘] = recv
        smtp = smtplib.SMTP(mail_host, port=port)   # 定义邮箱服务类型
        smtp.login(username, passwd)      # 登录邮箱
        smtp.sendmail(username, recv, msg.as_string())   #发送邮件
        smtp.quit()
        print(‘email 发送成功.‘)

if __name__ == ‘__main__‘:
    email_user = ‘1326*****@163.com‘  # 发送者账号
    email_pwd = ‘******‘  # 发送者密码,授权码
    maillist = ‘5****@qq.com‘   # 接收者邮箱
    title = ‘测试邮件标题‘
    content = ‘这里是邮件内容‘
    SendEmail().send_emil(email_user, email_pwd, maillist, title, content)

 

python3关于邮件的操作

原文:https://www.cnblogs.com/chosenone/p/10818574.html

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