javascript - 使用python获取空白电子邮件

标签 javascript html python-3.x

我正在尝试使用 python 发送电子邮件,但收到空白电子邮件,这是使用 css 文件和 js 文件

import smtplib
import urllib2
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import sys

server = "localhost"
sender = "send email id"
receivers = ["receiver email id"]
msg = MIMEMultipart('alternative')

SUBJECT = "devsmoke run"
msg['Subject'] = SUBJECT
msg['From'] = sender
msg['To'] = receivers
html = """ 
<html>
    <head>
        <script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>

        <!-- Latest compiled and minified CSS -->
        <link href="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.6/slate/bootstrap.min.css" rel="stylesheet" integrity="sha384-X9JiR5BtXUXiV6R3XuMyVGefFyy+18PHpBwaMfteb/vd2RrK6Gt4KPenkQyWLxCC" crossorigin="anonymous">

        <!-- Latest compiled and minified JavaScript -->
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>

        <!-- Local resources -->
        <link rel="stylesheet" href=".html/report.css">
        <script src=".html/report.js"></script>

        <!-- Reporting data -->
        <script src="report.js"></script>
    </head>
    <body>
    <div class="container-fluid" id="root"></div>
    </body>
</html>
"""
part2 = MIMEText(html, "html")
msg.attach(part2)
try:
    s = smtplib.SMTP(server)
    s.sendmail(sender, receivers, msg.as_string())
    s.quit()
    print("Successfully sent email")
except Exception, err:
    print(err)
    print("Error: unable to send email")

我收到电子邮件,但没有任何内容。文件report.js和.html目录与此python代码位于同一目录中

最佳答案

将邮件内容添加到 MIMEMultipart 对象。

msg.attach(MIMEText(html, "html")) # You can have html or text in content

关于javascript - 使用python获取空白电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58077849/

相关文章:

javascript - 工具提示:[data-tooltip-content]作为动态HTML的指针

onload 函数内的 Javascript 变量范围

javascript - 如何创建文本 slider

php - 打开带有动态内容的窗口

javascript - Ember 可折叠容器

python - 如何让python成功从互联网上下载大图片

javascript - 抑制 typescript 警告

javascript - 使用 JS 将 REST 数据附加到矩阵网格

python - 没有 html 标签时的 HTML 抓取

python-3.x - 尝试使用 get-metric-statistics 从 Lambda 从 Cloudwatch 获取 CPU 利用率指标时,响应为空