【问题标题】:python email update contentpython邮件更新内容
【发布时间】:2019-08-11 18:11:43
【问题描述】:

我有一个sn-p代码,在for循环中发送电子邮件,更新for循环中每次迭代的电子邮件内容。但电子邮件正文没有得到更新。请帮帮我。

我尝试添加 del 消息,但没有成功

for i in range(0,3) :
    data = [[i,i,i,i,i,]]+data
    print(data)
    text = text.format(table=tabulate(data, headers="firstrow", tablefmt="grid"))
    html = html.format(table=tabulate(data, headers="firstrow", tablefmt="html"))
    message = MIMEMultipart(
        "alternative", None, [MIMEText(text), MIMEText(html,'html')])
    #message.attach(MIMEText(html,'html'))i
    sub_time = datetime.datetime.now()+datetime.timedelta(hours=5,minutes=30)
    sub = "Time - "+str(sub_time.hour)+":"+str(sub_time.second)

    message['Subject'] = sub
    message['From'] = me
    message['To'] = you
    server.login(me, password)

    server.sendmail(me, you, message.as_string())

在邮件中,我得到了所有 3 次迭代的 0,0,0,0,0+数据。

【问题讨论】:

  • data的原始数据是什么?
  • 一些列表列表..不管数据(常量或变化),[[i,i,i,i,i]] 应该得到更新,但它没有发生
  • [[0, 0, 0, 0, 0]] 将始终存在于所有迭代中,因为您始终将 data 添加到其先前的值。换句话说,在您执行+ data 之后,上一次迭代中的[[i, i, i, i]] 将始终是下一次迭代中data 的一部分。如果您不希望数据自行堆积,请尝试不要重复使用data,而是分配给不同的变量iter_data = [[i, i, i, i]] + data
  • 电子邮件中显示了什么?你能给我们确切的文字吗?
  • 这是意料之中的......

标签: python html-email


【解决方案1】:
##text = text.format(table=tabulate(data, headers="firstrow", tablefmt="grid"))

text = format(tabulate(data, headers="firstrow", tablefmt="grid"))
##html = html.format(table=tabulate(data, headers="firstrow", tablefmt="html"))

html = format(tabulate(data, headers="firstrow", tablefmt="html"))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-24
    • 2017-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多