0

从上周开始,我正在尝试使用 pygal python 库创建一个简单的折线图并使用 mandrill api 发送生成的邮件。

我将渲染结果放在 pygal 文档中指定的“figure”标签中。

我可以发送电子邮件,但它完全是空白的。

以下是我的代码。

    line_chart = pygal.Line()
    line_chart.title = 'Browser usage evolution (in %)'
    line_chart.x_labels = map(str, range(2002, 2013))
    line_chart.add('Firefox', [None, None, 0, 16.6,   25,   31, 36.4, 45.5, 46.3, 42.8, 37.1])
    line_chart.add('Chrome',  [None, None, None, None, None, None,    0,  3.9, 10.8, 23.8, 35.3])
    line_chart.add('IE',      [85.8, 84.6, 84.7, 74.5,   66, 58.6, 54.7, 44.8, 36.2, 26.6, 20.1])
    line_chart.add('Others',  [14.2, 15.4, 15.3,  8.9,    9, 10.4,  8.9,  5.8,  6.7,  6.8,  7.5])
    chart = line_chart.render()

    html = """<html>
            <head>
            <script type="text/javascript" src="http://kozea.github.com/pygal.js/javascripts/svg.jquery.js"></script>
            <script type="text/javascript" src="http://kozea.github.com/pygal.js/javascripts/pygal-tooltips.js"></script>
            </head>
           <body>
            <figure>"""
    html += chart
    html += "</figure></body></html>"

    try:
        mandrill_client = mandrill.Mandrill(MANDRILL_API_KEY)
        message = {}
        message['from_email'] = constants.REPORTS
        message['subject'] = 'Sending report of non reporting gps devices.'

        for email_id in send_to:
            to_dict = {}
            to_dict['email'] = str(email_id)
            to.append(to_dict)

        message['to'] = to
        message['preserve_recipients'] = True                                   
        message['html'] = str(html)

        result = mandrill_client.messages.send(message=message, async=False, ip_pool=constants.MANDRILL_MAIN_POOL, send_at=constants.SEND_AT) 
    except mandrill.Error, e:
        print 'A mandrill error occurred: %s - %s' % (e.__class__, e)

谁能告诉我我在这里做错了什么?

4

1 回答 1

0

电子邮件客户端无法呈现 Javascript。您附加的图表需要由 pygal.js 呈现,由于电子邮件无法呈现 Javascript,因此失败。

于 2016-05-21T16:58:31.737 回答