2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > python 发送邮件附件很慢_python发送邮件附件

python 发送邮件附件很慢_python发送邮件附件

时间:2018-08-26 01:40:08

相关推荐

python 发送邮件附件很慢_python发送邮件附件

python发送邮件附件

完整示例:

import smtplib

import os

# from email.header import Header

from email.mime.text import MIMEText

from email.mime.multipart import MIMEMultipart

from email.mime.application import MIMEApplication

# 邮件配置

username = 'test@'

password = '123456'

def send_emails(subject=None,content=None,ex_file_path=None,to_emails=None):

msgRoot = MIMEMultipart('related')

msgRoot['Subject'] = "level"

if ex_file_path:

_file_name = os.path.basename(ex_file_path)

with open(ex_file_path, 'rb') as fp:

msgFile = MIMEApplication(fp.read())

msgFile["Content-Type"] = 'application/octet-stream'

msgFile.add_header('Content-Disposition', 'attachment', filename=('utf8', '', _file_name))

msgRoot.attach(msgFile)

# msgText = MIMEText(content, _subtype='html', _charset='utf-8')

msgRoot['From'] = "test"

msgRoot['To'] = ','.join(to_emails)

# msgRoot.attach(msgText)

try:

server = smtplib.SMTP_SSL('smtp.', 465)

server.login(username, password)

server.sendmail(username, to_emails, msgRoot.as_string())

print("sendEmail success")

except smtplib.SMTPException as e:

print("fail")

finally:

server.quit()

if __name__=='__main__':

send_emails(

subject="TEST EMAIL",

# content="RUN ERROR",

ex_file_path="output.xlsx",

to_emails=['test1@']

)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。