简体   繁体   English

使用mandrill API在邮件中发送pygal折线图

[英]send pygal line chart in mail using mandrill api

from past week I am trying to create a simple line chart using pygal python library & send the resulting mail using mandrill api. 从上周开始,我试图使用pygal python库创建一个简单的折线图,并使用mandrill api发送结果邮件。

I placed my render result in "figure" tag as specified in pygal documentation. 我将渲染结果放置在pygal文档中指定的“ figure”标签中。

I am able to send the email but it is completely blank. 我可以发送电子邮件,但完全空白。

following is my code. 以下是我的代码。

    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)

can anybody tell me what I am doing wrong here? 有人可以告诉我我在做什么错吗?

Email clients cannot render Javascript. 电子邮件客户端无法呈现Javascript。 The chart that you are attaching needs to be rendered by pygal.js, which fails since email cannot render Javascript. 您要附加的图表需要由pygal.js呈现,由于电子邮件无法呈现Javascript,该图表将失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM