CLI that lets you pipe output to email using SendGrid

Introduction

Very often you find yourself having to copy the output of asciidoctor and paste it into your mail client only to realize that it’s messed up by then.

Or sometimes you want to run some commands and take their output and automate emails.

May be you’re using Exchange and can’t really automate email without jumping through hoops.

Well, look no further; we now have mailcli.

Getting Started

You will have to sign up for a SendGrid account first. This will require you to use an email address that’s not a public mail server. Once you’re done signing up for your account, in your shell profile declare some environment variables

export SENDGRID_USER=<username>
export SENDGRID_PASS=<password>
export SENDGRID_FROM=sender@example.com

You could skip that and set your environment every time you want to run the mailcli command, but that ends up getting really painful.

Installation

You have several options to install mailcli

Go get

If you have already installed the go sdk on your machine and prefer using go get, you can use that.

go get github.com/rahulsom/mailcli

This is the preferred approach, beacuse you can then update it without giving it much thought.

However, setting up go is not for everyone, so there is the direct download approach.

Direct download

This is WIP. It hasn’t been tested in all platforms. If it does not work, please raise a bug on github issues.

386

amd64

arm

Darwin (Apple Mac)

FreeBSD

Debian

Other Linux

MS Windows

NetBSD

OpenBSD

DragonFly

NaCl

Solaris

Plan 9

Once you’ve downloaded the right archive for your platform, make sure the executable is in your path. Then you’re all set.

Usage

Help

To see help, say

mailcli -h

Text

cat testresult.txt | mailcli -to "foo@bar.com" -s "Test Result"

HTML

cat document.html | mailcli -to "foo@bar.com" -s "What's for lunch" -html

If the type is html, and the subject is not provided, it will be derived from the title of the document.

Asciidoctor

If you have asciidoctor installed, you could pipe that to an email too.

asciidoctor index.adoc -o - | mailcli -to "foo@bar.com" -html

Email Address Format

These are acceptable formats for emails

user@domain.com
Name <user@domain.com>
Very Long Name <user@domain.com>
"Name in quotes" <user@domain.com>

If you have multiple recipients in a field, you must separate them using commas. Not seimcolons

cat testresult.txt | mailcli \
        -to "foo@bar.com, Private Snafu<snafu@tarfu.com>, Fubar@tarfu.com" \
        -s "Test Result"