Log In

Instructions for setting up a Go wrapper around the SMTP2GO /email/send API endpoint.

Step 1

To install:

go get github.com/smtp2go-oss/smtp2go-go

Add the import in your source file:

import "github.com/smtp2go-oss/smtp2go-go"

Step 2

Log in to your SMTP2GO account and navigate to:

Sending -> API Keys

Create a new API key and make sure the /email/send endpoint is enabled.

Step 3

Once you have an API key, you need to export it into the environment where your Golang application is going to be executed. This can be done on the terminal like so:

$ export SMTP2GO_API_KEY=""

Or alternatively you can set it in code using the following:

import "os" os.Setenv("SMTP2GO_API_KEY", "<your_API_key>")

Step 4

Then, sending mail is as simple as:

package main

import (
"fmt"
"github.com/smtp2go-oss/smtp2go-go"
)

func main() {

email := smtp2go.Email{
From: "Matt ",
To: []string{
"Dave ",
},
Subject: "Trying out SMTP2GO",
TextBody: "Test Message",
HtmlBody: "

Test Message

",
}
res, err := smtp2go.Send(&email)
if err != nil {
fmt.Printf("An Error Occurred: %s", err)
}
fmt.Printf("Sent Successfully: %s", res)
}

Step 5

You can also send Asynchronously:

package main

import (
"fmt"
"github.com/smtp2go-oss/smtp2go-go"
)

func main() {

email := smtp2go.Email{
From: "Matt ",
To: []string{
"Dave ",
},
Subject: "Trying out SMTP2GO",
TextBody: "Test Message",
HtmlBody: "

Test Message

",
}

var c chan *smtp2go.SendAsyncResult = smtp2go.SendAsync(&email)
res := <-c
if res.Error != nil {
fmt.Printf("An Error Occurred: %s", res.Error)
}
fmt.Printf("Sent Successfully: %s", res.Result)
}

Ready for better email delivery?

Try SMTP2GO free for as long as you like:

Try SMTP2GO Free → Paid plans available for over 1,000 emails/month.