首页 > 编程语言 > 详细

python发邮件

时间:2020-01-02 22:16:42      阅读:104      评论:0      收藏:0      [点我收藏+]

参考:

G:\文档\开发\python\发邮件

https://www.jianshu.com/p/bc057b304a14

 

# -*- coding: utf-8 -*-
from ufile import filemanager, bucketmanager
from ufile import config
import time
import os
from email.mime.text import MIMEText
from email.header import Header
from email.mime.multipart import MIMEMultipart
import smtplib
import MySQLdb
import json

sender = ‘feng.hong@opay-inc.com‘
password = ‘xxx‘

def send_email(title, receivers, msg, attach_paths):
message = MIMEMultipart()
subject = title
message[‘Subject‘] = Header(subject, ‘utf-8‘)
message.attach(MIMEText(msg, ‘html‘, ‘utf-8‘))
for p in attach_paths:
if os.path.exists(p):
att = MIMEText(open(p, ‘r‘).read(), ‘plain‘, ‘utf-8‘)
att["Content-Type"] = ‘application/octet-stream‘
att["Content-Disposition"] = ‘attachment; filename="%s"‘ % p
message.attach(att)
try:
server = smtplib.SMTP_SSL(‘mail.opay-inc.com‘, 465)
# server.ehlo()
# server.starttls()
server.login(sender, password)
server.sendmail(sender, receivers, message.as_string())
print("邮件发送成功")
except smtplib.SMTPException as e:
print(e.message)

python发邮件

原文:https://www.cnblogs.com/hongfeng2019/p/12142069.html

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