标签:att imp art read sage ati email port mail
参考:
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)
标签:att imp art read sage ati email port mail
原文地址:https://www.cnblogs.com/hongfeng2019/p/12142069.html