python发邮件
Posted hongfeng2019
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python发邮件相关的知识,希望对你有一定的参考价值。
参考:
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发邮件的主要内容,如果未能解决你的问题,请参考以下文章