使用python电子邮件或其他模块在电子邮件中发送散景图

时间:2015-07-22 06:07:58

标签: javascript python html email bokeh

我有一个包含Bokeh图的完整html文件。现在我正在尝试使用python电子邮件模块发送该html。我只是使用这里给出的第三个例子:https://docs.python.org/2.7/library/email-examples.html(如何创建HTML消息......)

但这似乎只是给我发了一封空白的电子邮件。

我还尝试了其他一些包含嵌入式javascript的html。这看起来很好(JS禁用,我不在乎)。

有关可能发生的事情的任何线索以及我可以改变什么?

这是html:



<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Bokeh Scatter Plots</title>

        <link rel="stylesheet" href="http://cdn.pydata.org/bokeh/release/bokeh-0.9.0.min.css" type="text/css" />
        <script type="text/javascript" src="http://cdn.pydata.org/bokeh/release/bokeh-0.9.0.min.js"></script>

<script type="text/javascript">
    Bokeh.$(function() {
        var all_models = [{"attributes": {"line_color": {"value": "white"}, "fill_color": {"value": "#5ab738"}, "tags": [], "doc": null, "fill_alpha": {"value": 0.7}, "height": {"units": "data", "field": "z"}, "width": {"units": "data", "field": "width_cat"}, "y": {"field": "midz"}, "x": {"field": "catz"}, "id": "20b3f29b-629c-4d0d-a8ef-9bc05e5b178a"}, "type": "Rect", "id": "20b3f29b-629c-4d0d-a8ef-9bc05e5b178a"}, {"attributes": {"nonselection_glyph": null, "data_source": {"type": "ColumnDataSource", "id": "23913a89-b55a-4191-a5c3-3195acc7e1f4"}, "tags": [], "doc": null, "selection_glyph": null, "id": "5eda121f-edca-48cf-aed6-1e109b54b2ff", "glyph": {"type": "Rect", "id": "20b3f29b-629c-4d0d-a8ef-9bc05e5b178a"}}, "type": "GlyphRenderer", "id": "5eda121f-edca-48cf-aed6-1e109b54b2ff"}, {"attributes": {"geometries": [], "tags": [], "doc": null, "id": "c43afbcc-a846-4f33-a482-039a0fd206e8"}, "type": "ToolEvents", "id": "c43afbcc-a846-4f33-a482-039a0fd206e8"}, {"attributes": {"plot": {"subtype": "Chart", "type": "Plot", "id": "36f2771e-837b-4b64-b541-523ef126784b"}, "tags": [], "doc": null, "major_label_orientation": 0.7853981633974483, "axis_label": "categories", "formatter": {"type": "CategoricalTickFormatter", "id": "f27df891-c727-4511-af15-049332957dda"}, "ticker": {"type": "CategoricalTicker", "id": "9d14f049-833c-4895-bb18-a13fd30163a3"}, "id": "50005101-7498-4430-8b3e-fece52250277"}, "type": "CategoricalAxis", "id": "50005101-7498-4430-8b3e-fece52250277"}, {"subtype": "Chart", "type": "Plot", "id": "36f2771e-837b-4b64-b541-523ef126784b", "attributes": {"x_range": {"type": "FactorRange", "id": "46a7ffcd-19f4-4d8a-ae50-e01aa946b82e"}, "right": [], "above": [], "tags": [], "tools": [{"type": "PanTool", "id": "d6948ffa-b6f5-4379-a967-82dca90488a0"}, {"type": "WheelZoomTool", "id": "03df0ff2-3de4-4341-aecc-1bc593ebb8f2"}, {"type": "BoxZoomTool", "id": "3b6ab084-b09a-4131-809e-282113f78357"}, {"type": "PreviewSaveTool", "id": "8264e0e1-e9b3-44cd-aed7-02d01251240a"}, {"type": "ResizeTool", "id": "d3c48641-01cb-467c-91ee-3a0c6085d201"}, {"type": "ResetTool", "id": "3f0c4f54-5e2b-4253-b7e4-9bb9a7deabab"}, {"type": "HelpTool", "id": "3a1fb46c-8124-4374-83a4-2dd5bf4f6860"}], "title": "Bar example p", "renderers": [{"type": "CategoricalAxis", "id": "50005101-7498-4430-8b3e-fece52250277"}, {"type": "LinearAxis", "id": "42be7469-495b-4e8a-8021-a9a3191cecf0"}, {"type": "Grid", "id": "42bb2980-8afe-426d-9894-767dd3e4caad"}, {"type": "GlyphRenderer", "id": "8eb8810b-0e44-4851-89df-79debf7dbe2a"}, {"type": "GlyphRenderer", "id": "5eda121f-edca-48cf-aed6-1e109b54b2ff"}], "plot_width": 400, "extra_y_ranges": {}, "extra_x_ranges": {}, "tool_events": {"type": "ToolEvents", "id": "c43afbcc-a846-4f33-a482-039a0fd206e8"}, "plot_height": 400, "doc": null, "id": "36f2771e-837b-4b64-b541-523ef126784b", "y_range": {"type": "Range1d", "id": "90174572-530c-4de3-8906-e80952108b06"}, "below": [{"type": "CategoricalAxis", "id": "50005101-7498-4430-8b3e-fece52250277"}], "left": [{"type": "LinearAxis", "id": "42be7469-495b-4e8a-8021-a9a3191cecf0"}]}}, {"attributes": {"doc": null, "id": "9d14f049-833c-4895-bb18-a13fd30163a3", "tags": []}, "type": "CategoricalTicker", "id": "9d14f049-833c-4895-bb18-a13fd30163a3"}, {"attributes": {"doc": null, "id": "f27df891-c727-4511-af15-049332957dda", "tags": []}, "type": "CategoricalTickFormatter", "id": "f27df891-c727-4511-af15-049332957dda"}, {"attributes": {"plot": {"subtype": "Chart", "type": "Plot", "id": "36f2771e-837b-4b64-b541-523ef126784b"}, "tags": [], "doc": null, "axis_label": "values", "formatter": {"type": "BasicTickFormatter", "id": "a5efb989-af95-4129-983a-b867fe96eddf"}, "ticker": {"type": "BasicTicker", "id": "57a0ff59-725c-4d01-920a-2a3f8c65e6c4"}, "id": "42be7469-495b-4e8a-8021-a9a3191cecf0"}, "type": "LinearAxis", "id": "42be7469-495b-4e8a-8021-a9a3191cecf0"}, {"attributes": {"tags": [], "doc": null, "mantissas": [2, 5, 10], "id": "57a0ff59-725c-4d01-920a-2a3f8c65e6c4"}, "type": "BasicTicker", "id": "57a0ff59-725c-4d01-920a-2a3f8c65e6c4"}, {"attributes": {"plot": {"subtype": "Chart", "type": "Plot", "id": "36f2771e-837b-4b64-b541-523ef126784b"}, "tags": [], "doc": null, "dimension": 1, "ticker": {"type": "BasicTicker", "id": "57a0ff59-725c-4d01-920a-2a3f8c65e6c4"}, "id": "42bb2980-8afe-426d-9894-767dd3e4caad"}, "type": "Grid", "id": "42bb2980-8afe-426d-9894-767dd3e4caad"}, {"attributes": {"doc": null, "id": "a5efb989-af95-4129-983a-b867fe96eddf", "tags": []}, "type": "BasicTickFormatter", "id": "a5efb989-af95-4129-983a-b867fe96eddf"}, {"attributes": {"column_names": ["width_cat", "stackedz", "stackedy", "cat", "width", "zero", "midz", "midy", "y", "caty", "catz", "z"], "tags": [], "doc": null, "selected": {"2d": {"indices": []}, "1d": {"indices": []}, "0d": {"indices": [], "flag": false}}, "callback": null, "data": {"width_cat": [0.2, 0.2, 0.2, 0.2, 0.2], "stackedz": [6.5, 9.5, 8.0, 6.0, 6.0], "stackedy": [3.0, 3.5, 1.0, 2.0, 2.5], "cat": ["C1", "C2", "C3", "D1", "D2"], "width": [0.8, 0.8, 0.8, 0.8, 0.8], "zero": [7.0, 12.0, 14.0, 8.0, 7.0], "midz": [0.5, 2.5, 6.0, 2.0, 1.0], "midy": [3.0, 3.5, 1.0, 2.0, 2.5], "y": [6, 7, 2, 4, 5], "caty": ["C1:0.333333333333", "C2:0.333333333333", "C3:0.333333333333", "D1:0.333333333333", "D2:0.333333333333"], "catz": ["C1:0.666666666667", "C2:0.666666666667", "C3:0.666666666667", "D1:0.666666666667", "D2:0.666666666667"], "z": [1, 5, 12, 4, 2]}, "id": "23913a89-b55a-4191-a5c3-3195acc7e1f4"}, "type": "ColumnDataSource", "id": "23913a89-b55a-4191-a5c3-3195acc7e1f4"}, {"attributes": {"plot": {"subtype": "Chart", "type": "Plot", "id": "36f2771e-837b-4b64-b541-523ef126784b"}, "dimensions": ["width", "height"], "tags": [], "doc": null, "id": "d6948ffa-b6f5-4379-a967-82dca90488a0"}, "type": "PanTool", "id": "d6948ffa-b6f5-4379-a967-82dca90488a0"}, {"attributes": {"plot": {"subtype": "Chart", "type": "Plot", "id": "36f2771e-837b-4b64-b541-523ef126784b"}, "dimensions": ["width", "height"], "tags": [], "doc": null, "id": "03df0ff2-3de4-4341-aecc-1bc593ebb8f2"}, "type": "WheelZoomTool", "id": "03df0ff2-3de4-4341-aecc-1bc593ebb8f2"}, {"attributes": {"plot": {"subtype": "Chart", "type": "Plot", "id": "36f2771e-837b-4b64-b541-523ef126784b"}, "dimensions": ["width", "height"], "tags": [], "doc": null, "id": "3b6ab084-b09a-4131-809e-282113f78357"}, "type": "BoxZoomTool", "id": "3b6ab084-b09a-4131-809e-282113f78357"}, {"attributes": {"plot": {"subtype": "Chart", "type": "Plot", "id": "36f2771e-837b-4b64-b541-523ef126784b"}, "tags": [], "doc": null, "id": "8264e0e1-e9b3-44cd-aed7-02d01251240a"}, "type": "PreviewSaveTool", "id": "8264e0e1-e9b3-44cd-aed7-02d01251240a"}, {"attributes": {"plot": {"subtype": "Chart", "type": "Plot", "id": "36f2771e-837b-4b64-b541-523ef126784b"}, "tags": [], "doc": null, "id": "d3c48641-01cb-467c-91ee-3a0c6085d201"}, "type": "ResizeTool", "id": "d3c48641-01cb-467c-91ee-3a0c6085d201"}, {"attributes": {"plot": {"subtype": "Chart", "type": "Plot", "id": "36f2771e-837b-4b64-b541-523ef126784b"}, "tags": [], "doc": null, "id": "3f0c4f54-5e2b-4253-b7e4-9bb9a7deabab"}, "type": "ResetTool", "id": "3f0c4f54-5e2b-4253-b7e4-9bb9a7deabab"}, {"attributes": {"plot": {"subtype": "Chart", "type": "Plot", "id": "36f2771e-837b-4b64-b541-523ef126784b"}, "tags": [], "doc": null, "id": "3a1fb46c-8124-4374-83a4-2dd5bf4f6860"}, "type": "HelpTool", "id": "3a1fb46c-8124-4374-83a4-2dd5bf4f6860"}, {"attributes": {"callback": null, "factors": ["C1", "C2", "C3", "D1", "D2"], "doc": null, "tags": [], "id": "46a7ffcd-19f4-4d8a-ae50-e01aa946b82e"}, "type": "FactorRange", "id": "46a7ffcd-19f4-4d8a-ae50-e01aa946b82e"}, {"attributes": {"end": 13.200000000000001, "callback": null, "doc": null, "tags": [], "start": 0, "id": "90174572-530c-4de3-8906-e80952108b06"}, "type": "Range1d", "id": "90174572-530c-4de3-8906-e80952108b06"}, {"attributes": {"line_color": {"value": "white"}, "fill_color": {"value": "#f22c40"}, "tags": [], "doc": null, "fill_alpha": {"value": 0.7}, "height": {"units": "data", "field": "y"}, "width": {"units": "data", "field": "width_cat"}, "y": {"field": "midy"}, "x": {"field": "caty"}, "id": "43271b33-7e9c-4120-a177-4d0f1c233de1"}, "type": "Rect", "id": "43271b33-7e9c-4120-a177-4d0f1c233de1"}, {"attributes": {"nonselection_glyph": null, "data_source": {"type": "ColumnDataSource", "id": "23913a89-b55a-4191-a5c3-3195acc7e1f4"}, "tags": [], "doc": null, "selection_glyph": null, "id": "8eb8810b-0e44-4851-89df-79debf7dbe2a", "glyph": {"type": "Rect", "id": "43271b33-7e9c-4120-a177-4d0f1c233de1"}}, "type": "GlyphRenderer", "id": "8eb8810b-0e44-4851-89df-79debf7dbe2a"}];
        Bokeh.load_models(all_models);
        var plots = [{'modeltype': 'Plot', 'elementid': '#806c01c5-0a0d-4d12-9df9-5de64399e878', 'modelid': '36f2771e-837b-4b64-b541-523ef126784b'}];
        for (idx in plots) {
            var plot = plots[idx];
            var model = Bokeh.Collections(plot.modeltype).get(plot.modelid);
            Bokeh.logger.info('Realizing plot:')
            Bokeh.logger.info(' - modeltype: ' + plot.modeltype);
            Bokeh.logger.info(' - modelid: ' + plot.modelid);
            Bokeh.logger.info(' - elementid: ' + plot.elementid);
            var view = new model.default_view({
                model: model,
                el: plot.elementid
            });
            Bokeh.index[plot.modelid] = view;
        }
    });
</script>
    </head>
    <body>
<div class="plotdiv" id="806c01c5-0a0d-4d12-9df9-5de64399e878"></div>    </body>
</html>
&#13;
&#13;
&#13;

这是python脚本:

#!/usr/bin/env python

import smtplib

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

me = 'abc@mac.com'
you = 'abc@abc.com'

# Create message container - the correct MIME type is multipart/alternative.
msg = MIMEMultipart('alternative')
msg['Subject'] = "Link JavaScript big"
msg['From'] = me
msg['To'] = you

# Create the body of the message (a plain-text and an HTML version).
#text = "Hi!\nHow are you?\nHere is the link you wanted:\nhttps://www.python.org"

# example below
'''
html = """\ 
<!DOCTYPE html>
<html>
<body>

<h1>My First JavaScript</h1>

<button type="button"
onclick="document.getElementById('demo').innerHTML = Date()">
Click me to display Date and Time.</button>

<p id="demo"></p>

</body>
</html>
"""
'''

# html goes here
html = """\

"""


# Record the MIME types of both parts - text/plain and text/html.
#part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')

# Attach parts into message container.
# According to RFC 2046, the last part of a multipart message, in this case
# the HTML message, is best and preferred.
#msg.attach(part1)
msg.attach(part2)

# Send the message via local SMTP server.
s = smtplib.SMTP('localhost')
# sendmail function takes 3 arguments: sender's address, recipient's address
# and message to send - here it is sent as one string.
s.sendmail(me, you, msg.as_string())
s.quit()

散景html在评论下面的三重引号(就像它上面的例子一样)&#34; #html到这里&#34;

0 个答案:

没有答案