{"id":707,"date":"2014-05-06T12:00:48","date_gmt":"2014-05-06T16:00:48","guid":{"rendered":"https:\/\/reviewsignal.com\/blog\/?p=707"},"modified":"2014-07-20T23:35:47","modified_gmt":"2014-07-21T03:35:47","slug":"how-to-send-email-from-the-command-line-with-sendgrid","status":"publish","type":"post","link":"https:\/\/reviewsignal.com\/blog\/2014\/05\/06\/how-to-send-email-from-the-command-line-with-sendgrid\/","title":{"rendered":"How to send email from the command line with SendGrid"},"content":{"rendered":"<p>Sending email should be simple. It's something I really don't like thinking about.<\/p>\n<p>I ran into an issue where I wanted to send email from the command line in a bash script that helps power Review Signal. A notification when something goes wrong.<\/p>\n<p>The only problem, I don't have any mailing program installed. I also don't really want to send email from my servers because making sure they get through isn't something I want to spend a lot of time thinking about.<\/p>\n<p>The first solution that jumped to mind was <a href=\"http:\/\/sendgrid.com\">SendGrid<\/a>, who I had the pleasure of trying out their API at <a href=\"https:\/\/2013.battlehack.org\/washington\/\">PayPal BattleHack DC<\/a>. It was dead simple. I had integrated it into PHP though. I didn't know if it worked from the command line.<\/p>\n<p>I checked the <a href=\"https:\/\/sendgrid.com\/docs\/API_Reference\/Web_API\/mail.html\">docs<\/a> and found they had a rest API.<\/p>\n\n<div class=\"wp_syntax\"><table><tr><td class=\"code\"><pre class=\"bash\" style=\"font-family:monospace;\">curl <span style=\"color: #660033;\">-d<\/span> <span style=\"color: #ff0000;\">'to=destination@example.com&amp;toname=Destination&amp;subject=Example Subject&amp;text=testingtextbody&amp;from=info@domain.com&amp;api_user=your_sendgrid_username&amp;api_key=your_sendgrid_password'<\/span> https:<span style=\"color: #000000; font-weight: bold;\">\/\/<\/span>api.sendgrid.com<span style=\"color: #000000; font-weight: bold;\">\/<\/span>api<span style=\"color: #000000; font-weight: bold;\">\/<\/span>mail.send.json<\/pre><\/td><\/tr><\/table><\/div>\n\n<p>If you want to clean it up with variables:<\/p>\n\n<div class=\"wp_syntax\"><table><tr><td class=\"code\"><pre class=\"bash\" style=\"font-family:monospace;\"><span style=\"color: #666666; font-style: italic;\">#!\/bin\/sh<\/span>\n<span style=\"color: #007800;\">SGTO<\/span>=receiver<span style=\"color: #000000; font-weight: bold;\">@<\/span>example.com\n<span style=\"color: #007800;\">SGTONAME<\/span>=<span style=\"color: #ff0000;\">'Some Name'<\/span>\n<span style=\"color: #007800;\">SGSUBJECT<\/span>=<span style=\"color: #ff0000;\">'Email Subject'<\/span>\n<span style=\"color: #007800;\">SGFROM<\/span>=from<span style=\"color: #000000; font-weight: bold;\">@<\/span>example.com\n<span style=\"color: #007800;\">SGTEXT<\/span>=<span style=\"color: #ff0000;\">'Email Text'<\/span>\n<span style=\"color: #007800;\">SGUSER<\/span>=user\n<span style=\"color: #007800;\">SGPASS<\/span>=password\ncurl <span style=\"color: #660033;\">-d<\/span> <span style=\"color: #ff0000;\">&quot;to=<span style=\"color: #007800;\">${SGTO}<\/span>&amp;toname=<span style=\"color: #007800;\">${SGTONAME}<\/span>&amp;subject=<span style=\"color: #007800;\">${SGSUBJECT}<\/span>&amp;text=<span style=\"color: #007800;\">${SGTEXT}<\/span>&amp;from=<span style=\"color: #007800;\">${SGFROM}<\/span>&amp;api_user=<span style=\"color: #007800;\">${SGUSER}<\/span>&amp;api_key=<span style=\"color: #007800;\">${SGPASS}<\/span>&quot;<\/span> https:<span style=\"color: #000000; font-weight: bold;\">\/\/<\/span>api.sendgrid.com<span style=\"color: #000000; font-weight: bold;\">\/<\/span>api<span style=\"color: #000000; font-weight: bold;\">\/<\/span>mail.send.json<\/pre><\/td><\/tr><\/table><\/div>\n\n<p>Voila! Sending emails from my bash script is now simple.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sending email should be simple. It&#8217;s something I really don&#8217;t like thinking about. I ran into an issue where I wanted to send email from the command line in a bash script that helps power Review Signal. A notification when something goes wrong. The only problem, I don&#8217;t have any mailing program installed. I also [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[66],"tags":[44,120,118,119],"class_list":["post-707","post","type-post","status-publish","format-standard","hentry","category-how-tuesday","tag-bash","tag-email","tag-sendgrid","tag-shell"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.3 - aioseo.com -->\n\t<meta name=\"robots\" content=\"max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n\t<meta name=\"author\" content=\"Kevin Ohashi\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/reviewsignal.com\/blog\/2014\/05\/06\/how-to-send-email-from-the-command-line-with-sendgrid\/\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.3\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Review Signal Blog\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"How to send email from the command line with SendGrid | Review Signal Blog\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/reviewsignal.com\/blog\/2014\/05\/06\/how-to-send-email-from-the-command-line-with-sendgrid\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2014-05-06T16:00:48+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2014-07-21T03:35:47+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"How to send email from the command line with SendGrid | Review Signal Blog\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/2014\\\/05\\\/06\\\/how-to-send-email-from-the-command-line-with-sendgrid\\\/#article\",\"name\":\"How to send email from the command line with SendGrid | Review Signal Blog\",\"headline\":\"How to send email from the command line with SendGrid\",\"author\":{\"@id\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/author\\\/kohashi\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/#organization\"},\"datePublished\":\"2014-05-06T12:00:48-04:00\",\"dateModified\":\"2014-07-20T23:35:47-04:00\",\"inLanguage\":\"en-US\",\"commentCount\":10,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/2014\\\/05\\\/06\\\/how-to-send-email-from-the-command-line-with-sendgrid\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/2014\\\/05\\\/06\\\/how-to-send-email-from-the-command-line-with-sendgrid\\\/#webpage\"},\"articleSection\":\"How-Tuesday, bash, email, sendgrid, shell\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/2014\\\/05\\\/06\\\/how-to-send-email-from-the-command-line-with-sendgrid\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/category\\\/how-tuesday\\\/#listItem\",\"name\":\"How-Tuesday\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/category\\\/how-tuesday\\\/#listItem\",\"position\":2,\"name\":\"How-Tuesday\",\"item\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/category\\\/how-tuesday\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/2014\\\/05\\\/06\\\/how-to-send-email-from-the-command-line-with-sendgrid\\\/#listItem\",\"name\":\"How to send email from the command line with SendGrid\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/2014\\\/05\\\/06\\\/how-to-send-email-from-the-command-line-with-sendgrid\\\/#listItem\",\"position\":3,\"name\":\"How to send email from the command line with SendGrid\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/category\\\/how-tuesday\\\/#listItem\",\"name\":\"How-Tuesday\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/#organization\",\"name\":\"Review Signal Blog\",\"url\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/author\\\/kohashi\\\/#author\",\"url\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/author\\\/kohashi\\\/\",\"name\":\"Kevin Ohashi\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/2014\\\/05\\\/06\\\/how-to-send-email-from-the-command-line-with-sendgrid\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a62947400dd8e40200dee3dc620c62f8a9770e88a4e1185fd17bbcbf624525a6?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Kevin Ohashi\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/2014\\\/05\\\/06\\\/how-to-send-email-from-the-command-line-with-sendgrid\\\/#webpage\",\"url\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/2014\\\/05\\\/06\\\/how-to-send-email-from-the-command-line-with-sendgrid\\\/\",\"name\":\"How to send email from the command line with SendGrid | Review Signal Blog\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/2014\\\/05\\\/06\\\/how-to-send-email-from-the-command-line-with-sendgrid\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/author\\\/kohashi\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/author\\\/kohashi\\\/#author\"},\"datePublished\":\"2014-05-06T12:00:48-04:00\",\"dateModified\":\"2014-07-20T23:35:47-04:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/\",\"name\":\"Review Signal Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/reviewsignal.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"How to send email from the command line with SendGrid | Review Signal Blog","description":"","canonical_url":"https:\/\/reviewsignal.com\/blog\/2014\/05\/06\/how-to-send-email-from-the-command-line-with-sendgrid\/","robots":"max-snippet:-1, max-image-preview:large, max-video-preview:-1","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/reviewsignal.com\/blog\/2014\/05\/06\/how-to-send-email-from-the-command-line-with-sendgrid\/#article","name":"How to send email from the command line with SendGrid | Review Signal Blog","headline":"How to send email from the command line with SendGrid","author":{"@id":"https:\/\/reviewsignal.com\/blog\/author\/kohashi\/#author"},"publisher":{"@id":"https:\/\/reviewsignal.com\/blog\/#organization"},"datePublished":"2014-05-06T12:00:48-04:00","dateModified":"2014-07-20T23:35:47-04:00","inLanguage":"en-US","commentCount":10,"mainEntityOfPage":{"@id":"https:\/\/reviewsignal.com\/blog\/2014\/05\/06\/how-to-send-email-from-the-command-line-with-sendgrid\/#webpage"},"isPartOf":{"@id":"https:\/\/reviewsignal.com\/blog\/2014\/05\/06\/how-to-send-email-from-the-command-line-with-sendgrid\/#webpage"},"articleSection":"How-Tuesday, bash, email, sendgrid, shell"},{"@type":"BreadcrumbList","@id":"https:\/\/reviewsignal.com\/blog\/2014\/05\/06\/how-to-send-email-from-the-command-line-with-sendgrid\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/reviewsignal.com\/blog\/#listItem","position":1,"name":"Home","item":"https:\/\/reviewsignal.com\/blog\/","nextItem":{"@type":"ListItem","@id":"https:\/\/reviewsignal.com\/blog\/category\/how-tuesday\/#listItem","name":"How-Tuesday"}},{"@type":"ListItem","@id":"https:\/\/reviewsignal.com\/blog\/category\/how-tuesday\/#listItem","position":2,"name":"How-Tuesday","item":"https:\/\/reviewsignal.com\/blog\/category\/how-tuesday\/","nextItem":{"@type":"ListItem","@id":"https:\/\/reviewsignal.com\/blog\/2014\/05\/06\/how-to-send-email-from-the-command-line-with-sendgrid\/#listItem","name":"How to send email from the command line with SendGrid"},"previousItem":{"@type":"ListItem","@id":"https:\/\/reviewsignal.com\/blog\/#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/reviewsignal.com\/blog\/2014\/05\/06\/how-to-send-email-from-the-command-line-with-sendgrid\/#listItem","position":3,"name":"How to send email from the command line with SendGrid","previousItem":{"@type":"ListItem","@id":"https:\/\/reviewsignal.com\/blog\/category\/how-tuesday\/#listItem","name":"How-Tuesday"}}]},{"@type":"Organization","@id":"https:\/\/reviewsignal.com\/blog\/#organization","name":"Review Signal Blog","url":"https:\/\/reviewsignal.com\/blog\/"},{"@type":"Person","@id":"https:\/\/reviewsignal.com\/blog\/author\/kohashi\/#author","url":"https:\/\/reviewsignal.com\/blog\/author\/kohashi\/","name":"Kevin Ohashi","image":{"@type":"ImageObject","@id":"https:\/\/reviewsignal.com\/blog\/2014\/05\/06\/how-to-send-email-from-the-command-line-with-sendgrid\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/a62947400dd8e40200dee3dc620c62f8a9770e88a4e1185fd17bbcbf624525a6?s=96&d=mm&r=g","width":96,"height":96,"caption":"Kevin Ohashi"}},{"@type":"WebPage","@id":"https:\/\/reviewsignal.com\/blog\/2014\/05\/06\/how-to-send-email-from-the-command-line-with-sendgrid\/#webpage","url":"https:\/\/reviewsignal.com\/blog\/2014\/05\/06\/how-to-send-email-from-the-command-line-with-sendgrid\/","name":"How to send email from the command line with SendGrid | Review Signal Blog","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/reviewsignal.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/reviewsignal.com\/blog\/2014\/05\/06\/how-to-send-email-from-the-command-line-with-sendgrid\/#breadcrumblist"},"author":{"@id":"https:\/\/reviewsignal.com\/blog\/author\/kohashi\/#author"},"creator":{"@id":"https:\/\/reviewsignal.com\/blog\/author\/kohashi\/#author"},"datePublished":"2014-05-06T12:00:48-04:00","dateModified":"2014-07-20T23:35:47-04:00"},{"@type":"WebSite","@id":"https:\/\/reviewsignal.com\/blog\/#website","url":"https:\/\/reviewsignal.com\/blog\/","name":"Review Signal Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/reviewsignal.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"Review Signal Blog","og:type":"article","og:title":"How to send email from the command line with SendGrid | Review Signal Blog","og:url":"https:\/\/reviewsignal.com\/blog\/2014\/05\/06\/how-to-send-email-from-the-command-line-with-sendgrid\/","article:published_time":"2014-05-06T16:00:48+00:00","article:modified_time":"2014-07-21T03:35:47+00:00","twitter:card":"summary","twitter:title":"How to send email from the command line with SendGrid | Review Signal Blog"},"aioseo_meta_data":{"post_id":"707","title":null,"description":null,"keywords":null,"keyphrases":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_custom_url":null,"og_image_custom_fields":null,"og_image_url":null,"og_image_width":null,"og_image_height":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_image_url":null,"twitter_title":null,"twitter_description":null,"schema_type":"default","schema_type_options":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null,"created":"2026-11-03 20:31:25","updated":"2026-11-03 20:31:25"},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/reviewsignal.com\/blog\/\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/reviewsignal.com\/blog\/category\/how-tuesday\/\" title=\"How-Tuesday\">How-Tuesday<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tHow to send email from the command line with SendGrid\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/reviewsignal.com\/blog\/"},{"label":"How-Tuesday","link":"https:\/\/reviewsignal.com\/blog\/category\/how-tuesday\/"},{"label":"How to send email from the command line with SendGrid","link":"https:\/\/reviewsignal.com\/blog\/2014\/05\/06\/how-to-send-email-from-the-command-line-with-sendgrid\/"}],"_links":{"self":[{"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/posts\/707","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/comments?post=707"}],"version-history":[{"count":6,"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/posts\/707\/revisions"}],"predecessor-version":[{"id":757,"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/posts\/707\/revisions\/757"}],"wp:attachment":[{"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/media?parent=707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/categories?post=707"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/reviewsignal.com\/blog\/wp-json\/wp\/v2\/tags?post=707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}