How to Use SparkPost in Go

Dave Gray
Nov. 29, 2017 by Dave Gray

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

Related Content

Email Events On Your Terms: Webhooks, Databases, AWS, and more!

How can Webhooks be easier and searching event data even greater? We tackle webhooks, databases, AWS, and more in this post about tracking email events.

read more

Getting Started with C# and SparkPost

Sending email is a common need for C# applications. Use this guide and learn how to easily start sending email with C# and SparkPost.

read more

Using the SparkPost Metrics API with C#

Learn how to query the SparkPost API for information and metrics on the emails you’re sending using the C# wrapper and gain valuable insights.

read more

Get started and start sending

Try SparkPost and see how easy it is to deliver your app’s email on time and to the inbox.

Try Now

Send this to a friend