2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > python 东哥 with open_python 发送附件

python 东哥 with open_python 发送附件

时间:2020-03-02 05:25:32

相关推荐

python 东哥 with open_python 发送附件

#!/usr/bin/env python

# encoding: utf-8

#@author: 东哥加油!

#@file: sksendmail.py

#@time: /8/20 13:37

import smtplib

from email.mime.image import MIMEImage

from email.mime.multipart import MIMEMultipart

from email.mime.text import MIMEText

from email.header import Header

import datetime

import os

import subprocess

def sendmail(sbuject,text,to_addr,fj_rk_path,pdate):

msg = MIMEMultipart()

from_addr = 'frommail@'

password = 'xxxxx'

msg['Subject'] = Header(sbuject, 'utf-8').encode()

msg_text = MIMEText(text, 'plain', 'utf-8')

msg.attach(msg_text)

att1 = MIMEText(open(fj_rk_path, 'rb').read(), 'base64', 'utf-8')

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

att1["Content-Disposition"] = "attachment;filename=" + 'count'+str(pdate)+'.html'

#添加附件

msg.attach(att1)

smtp_server = ''

server = smtplib.SMTP(smtp_server, 587)

server.starttls()

server.login(from_addr, password)

server.sendmail(from_addr, [to_addr], msg.as_string())

server.quit()

if __name__ == '__main__':

subprocess.call('/bin/bash /home/ok/count.sh', shell=True)

cmd = 'find /home/ok/tmp/ -name *.html | sort -nr | head -1'

file_name = subprocess.getoutput(cmd)

mail_title = os.path.basename(file_name)

now_time = datetime.datetime.now()

pdate = now_time.strftime('%Y%m%d')

sendmail( mail_title, '详见附件', 'xxxx@', file_name, pdate)

sendmail( mail_title, '详见附件', 'xxxx@', file_name, pdate)

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