Introducing the Golang Send Email Package

Golang send email

At SocketLabs, we recently built a Golang Send Email Package to make it easier for Go developers to integrate with our injection API with minimal friction, while still allowing package consumers to harness all the powerful capabilities that our send email API stands to offer. Additionally, this package allows developers to use golang to send email without SMTP.

In this post, we’ll discuss some of our design choices and experiences in creating the golang email package.

How We Minimized Developer Friction While Building the Golang Send Email Package

With minimal developer friction in mind, we split the two main use cases our Injection API fulfills into two separate method calls on `ISocketlabsClient`: ‘SendBasic()`, and `SendBulk()`.

While `SendBasic()` is intended for messages similar to those created in a personal email client such as Outlook, `SendBulk` supports merge data and sends such that each recipient receives their own individual message.

By splitting these two send styles, we were able to abstract away some of the subtleties in how the Injection API handles input and distinguishes between these two types of sends. Having two distinct methods also allows us to restrict input to message types specific to the target use case. For example, `SendBulk()` accepts the `BulkMessage` type which accepts recipient merge data, but does not accept Cc or Bcc recipients.

Our Golang Send Email Package Gives Developers More Control

While other packages may force one into using something such as environment variables to pass credentials, we decided to leave control to package consumers in how they wish to manage credentials. For that reason, our client constructor function keeps things simple and accepts strings as input into our client constructor function. We feel it is better to give package consumers control over how they manage credentials.

For the examples that have been provided, each is hosted in its own Go main package which is a slight departure from some of the other libraries we have created where a runner is provided to select and execute examples. In this case, we knew it would be easier to allow users to find and run the individual examples, without complicating execution and debugging with a runner.

Building the Golang Send Email Package Was a Successful First Foray Into Golang Development

This is admittedly our development team’s first foray into Golang development so there were certainly hiccups along the way as we adjusted to the language. One interesting bump we encountered along the way was organizing our source code folder structure as we had done in our C# library. The Go compiler taught us through cyclic dependency errors that packages in Golang are not merely a naming organizational utility equivalent to C# namespaces (as we tried to use them), but more so a compiled unit closer in utility to a C# assembly. Though we met a few challenges, we eventually gained traction on the Golang development learning curve and our final product is a professional package you would expect from SocketLabs.

Any feedback is welcome and would best be done through our git repository here:

To learn more about sending email using Golang, visit our Go Package here.

For more examples and use cases check out our GitHub page.

If you’d like to learn more about our APIs for sending email then visit our Developer Hub.

Table of Contents