Python把数据写进html的表格代码里,收件人显示表格

获取数据之后,如何能把数据写进HTML的代码里,并直接发送给邮箱


import smtplib
from email.mime.text import MIMEText
import os,datetime
import tkinter
import tkinter.messagebox #弹窗库
from datetime import *
  
def send_miles(file_nei):
    mailserver = "smtp.163.com"  #邮箱服务器地址
    username_send = '*******@163.com'  #邮箱用户名
    password = 'M*****'   #邮箱密码:需要使用授权码
    username_recv = ['187**03**@qq.com','******@qq.com'] #收件人,多个收件人用逗号隔开--
    mail = MIMEText(file_nei,_subtype='html',_charset='utf-8')
    mail['Subject'] = '重要提醒'
    mail['From'] = username_send  #发件人
    mail['To'] = ",".join(username_recv)  #收件人;[]里的三个是固定写法,别问为什么,我只是代码的搬运工
    smtp = smtplib.SMTP(mailserver,port=25) # 连接邮箱服务器,smtp的端口号是25
    # smtp=smtplib.SMTP_SSL('smtp.qq.com',port=465) #QQ邮箱的服务器和端口号
    smtp.login(username_send,password)  #登录邮箱
    smtp.sendmail(username_send,username_recv,mail.as_string())# 参数分别是发送者,接收者,第三个是把上面的发送邮件的内容变成字符串
    smtp.quit() # 发送完毕后退出smtp
    print ('success')


def huoqu_html(yuanzu,zhuti):   
    # d = datetime.now()
    # dt = d.strftime('%Y-%m-%d %H:%M:%S')
    # at = (d - timedelta(1)).strftime('%Y-%m-%d %H:%M:%S')

    html = \
    """
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>"""+zhuti+"""</title>
    <body>
    <div id="container">
      <p><strong>"""+zhuti+"""</strong></p>
      <div id="content">
       <table width="90%" border="2" bordercolor="red" cellspacing="2" style="border-collapse:collapse">
      <tr>
        <td><strong>单号</strong></td>
        <td><strong>备注名</strong></td>
        <td><strong>比例</strong></td>
        <td><strong>净值</strong></td>
        <td><strong>余额</strong></td>
        <td><strong>盈亏</strong></td>
        <td><strong>更新时间</strong></td>
      </tr>
      """
    thbodys=""
    for a in yuanzu:
        if len(a)>0:
            thbody =\
              """
              <tr>
                <td>""" + str(a[1]) + """</td>
                <td>""" + str(a[2]) + """</td>
                <td>""" + str(a[4]) + """</td>
                <td>""" + str(a[5]) + """</td>
                <td>""" + str(a[6]) + """</td>
                <td>""" + str(a[7]) + """</td> 
                <td>""" + str(a[0]) + """</td> 
                        
              </tr>
              """
            thbodys=thbody+thbodys
    weiba=  \
    """
    </table>
      </div>
    </div>
    </div>
    </body>
    </html>
            """
    neirong_html = html+thbodys+weiba       
    return neirong_html



    yuanzu_1=(('da',23,45,58,99,88,988,999,555,2343),('dad',335,77,13,65,77,88,558,4458,99878,558),())
    if len(yuanzu_1)>1:
        neirong = huoqu_html(yuanzu_1,'特别关注')
        send_miles(neirong)

根据这个功能,就可以直接把获取 的数据,发送到邮箱进行储存。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值