{"id":26,"date":"2015-12-11T12:18:28","date_gmt":"2015-12-11T12:18:28","guid":{"rendered":"http:\/\/www.sqldashboards.com\/b\/?p=26"},"modified":"2015-12-11T12:18:28","modified_gmt":"2015-12-11T12:18:28","slug":"send-email-with-graphs","status":"publish","type":"post","link":"https:\/\/www.sqldashboards.com\/b\/send-email-with-graphs\/","title":{"rendered":"Sending an email with pie charts and graphs"},"content":{"rendered":"<p>The following steps explain how to send an email with chart image attachments from the command line. First we must install the necessary email tools in linux:<\/p>\n<h4>Install Email Sending on Linux<\/h4>\n<p><code><br \/>\napt-get install mutt<br \/>\nvi ~\/.muttrc<br \/>\n<\/code><\/p>\n<p>That last line, opens the configuration for editing. For gmail you will have details like this:<br \/>\n<code><br \/>\naccount-hook imap:\/\/gmail\/ \u201cset<\/p>\n<p>set imap_user = 'user@domain.com'<br \/>\nset imap_pass = 'PASSWORD'<\/p>\n<p>set smtp_url = 'smtp:\/\/user@domain.com@smtp.gmail.com:587\/'<\/p>\n<p>set smtp_pass = 'PASSWORD'<br \/>\nset from = 'user@domain.com'<br \/>\nset realname = 'John'<\/p>\n<p>set folder = 'imaps:\/\/imap.gmail.com:993'<br \/>\nset mbox= '+Inbox'<br \/>\nset spoolfile= '+Inbox'<br \/>\nset postponed= '+[Gmail]\/Drafts'<br \/>\nset trash = '+[Google Mail]\/Trash'<\/p>\n<p>set header_cache=~\/.mutt\/cache\/headers<br \/>\nset message_cachedir=~\/.mutt\/cache\/bodies<br \/>\nset certificate_file=~\/.mutt\/certificates<\/p>\n<p>set move = no<br \/>\nset timeout=15<br \/>\nauto_view text\/html<br \/>\n<\/code><\/p>\n<p>To test this, first run &#8220;mutt&#8221;, it should display your gmail inbox. Then send an email using the command:<br \/>\n<code>mutt -s \"test\" receiver@domain.com <<< \"test message\"<\/code><\/p>\n<h4>Install sqlChart and generate pie charts<\/h4>\n<ol>\n<li>Download <a href=\"http:\/\/www.sqldashboards.com\/files\/sqldashboards.jar\">sqlDashboards.jar<\/a><\/li>\n<li>Copy it to your \/usr\/local\/bin directory<\/li>\n<li>Create an alias so we can run it with a shorter name<\/li>\n<li>Run command to generate chart<\/li>\n<\/ol>\n<p><code><br \/>\nwget http:\/\/www.sqldashboards.com\/files\/sqldashboards.jar<br \/>\nmv sqldashboards.jar \/usr\/local\/bin\/<br \/>\nalias sqlchart=\"java -cp \/usr\/local\/bin\/sqldashboards.jar  com.timestored.sqldash.SqlChart\"<\/p>\n<p>sqlchart  --servertype mysql --chart piechart --user USERNAME --password PASSWORD --database DATABASENAME--out pie.png --execute \"select DATE(time),count(*) from qstudioreg group by DATE(time) ORDER BY DATE(time) DESC  limit 9\"<br \/>\n<\/code><\/p>\n<p>Voila we have our chart:<br \/>\n<a href=\"http:\/\/www.sqldashboards.com\/b\/wp-content\/uploads\/2015\/12\/pie.png\"><img loading=\"lazy\" src=\"http:\/\/www.sqldashboards.com\/b\/wp-content\/uploads\/2015\/12\/pie.png\" alt=\"database piechart\" width=\"400\" height=\"300\" class=\"alignnone size-full wp-image-32\" \/><\/a><\/p>\n<h4>Send email with attachments<\/h4>\n<p>Use mutt to send the email, with -a to specify attachments like so:<br \/>\n<code> mutt -s \"sql pie chart reports\" ryan@timestored.com  -a pie.png <<< \"Here is your database report\"<\/code><\/p>\n<p>Done. So we successfully configured mutt for sending email, then generated our pie chart from mysql using <a href=\"www.sqldashboards.com\/sqlchart\">sqlchart<\/a> then we emailed it as an attachment. If you have any problems please let me know and I'll try to help. Here's the email in my inbox:<\/p>\n<p><a href=\"http:\/\/www.sqldashboards.com\/b\/wp-content\/uploads\/2015\/12\/mail.png\"><img loading=\"lazy\" src=\"http:\/\/www.sqldashboards.com\/b\/wp-content\/uploads\/2015\/12\/mail.png\" alt=\"mail\" width=\"691\" height=\"411\" class=\"alignnone size-full wp-image-35\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The following steps explain how to send an email with chart image attachments from the command line. First we must install the necessary email tools in linux: Install Email Sending on Linux apt-get install mutt vi ~\/.muttrc That last line, opens the configuration for editing. For gmail you will have details like this: account-hook imap:\/\/gmail\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.sqldashboards.com\/b\/wp-json\/wp\/v2\/posts\/26"}],"collection":[{"href":"https:\/\/www.sqldashboards.com\/b\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqldashboards.com\/b\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqldashboards.com\/b\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqldashboards.com\/b\/wp-json\/wp\/v2\/comments?post=26"}],"version-history":[{"count":9,"href":"https:\/\/www.sqldashboards.com\/b\/wp-json\/wp\/v2\/posts\/26\/revisions"}],"predecessor-version":[{"id":37,"href":"https:\/\/www.sqldashboards.com\/b\/wp-json\/wp\/v2\/posts\/26\/revisions\/37"}],"wp:attachment":[{"href":"https:\/\/www.sqldashboards.com\/b\/wp-json\/wp\/v2\/media?parent=26"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqldashboards.com\/b\/wp-json\/wp\/v2\/categories?post=26"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqldashboards.com\/b\/wp-json\/wp\/v2\/tags?post=26"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}