码迷,mamicode.com
首页 > 编程语言 > 详细

python发邮件

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

标签: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)

python发邮件

标签:att   imp   art   read   sage   ati   email   port   mail   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!