Sending Gopher Emails

So you want to send some email. And you’re using Go. Do I have some great news for you! I have done this, and you can too. We’re going to build a tool that I’ve appropriately named send-a-gopher which, unsurprisingly, sends you (well, somebody) a gopher.

This tutorial assumes you already have a SparkPost account and have created an API key. And that you’ve got Go installed on your system.

First! Pick a gopher to send

This is undoubtedly the hardest part. After careful consideration, and a quick right click, copy image address, there’s your gopher. Oh, right. We need some code too.

Et voila! An extremely limited in-memory version of curl/wget/etc! We can now get gophers.

Second! Set up the SparkPost package

Installing the package is arguably the easiest part:

And that’s it. Next we’ll import and configure the SparkPost package:

Third! Encase the gopher in code

We’ll get it from the HTTP response, wrap it up in an InlineImage and some Content, then send that off in a Transmission:



Last! Send, and admire your handiwork

This is the second easiest part:

Er, you get the idea.

Look at you now. With a free account and just a little bit of code, you’re sending yourself gophers. That was pretty easy, and there are more sending examples in our GitHub repository, specifically in the sparks tool, along with the complete version of the code we’ve dissected here. It even handles errors.

-Dave Gray