How to send test email in Go

Introduction - sending email in Go

If you're writing software using Go, you're probably sending emails, either as part of sign up flows, or for sending notifications or maybe you just like sending pictures of Chameleons!

The standard way to send email is via an SMTP server, usually hosted by a specialist email service provider but can also be hosted yourself.

Sending email in Go is simple with the net/smtp package. The Go SMTP client automatically negotiates an encrypted connection using STARTTLS when using SendMail, which is compatible with Imitate Email and ensures that your credentials are encrypted.

The following code illustrates how to send an email:

package main

import (

func main() {
  // hostname is used by PlainAuth to validate the TLS certificate.
  hostname := ""
  auth := smtp.PlainAuth("", "username", "password", hostname)

  msg := `To:
Subject: Imitate Email using GoLang

This is the message content!
  err := smtp.SendMail(hostname+":587", auth, "", []string{""},
  if err != nil {

Sending Test Email: Set up Imitate Email

If you've not already done so please sign up to Imitate Email.

For Imitate Email, when sending test emails you use the following server details:

Port: 587

For your username and password you need to decide if you're using your personal mailbox or have set up a project in Imitate Email.

Locate your mailbox credentials

Your username

To locate your username go to Settings > My Mailbox where you will find it (it is the same for all mailboxes in your account)

For the password

If you're on the Free or Developer plan or you're setting this up for your personal mailbox copy the password from the same place as the username.

If you're setting this up for a team mailbox go to Settings > Projects and you will find the password next to the symbol for your mailbox. It will look like the following 6bcb69b2-08ac-4c67-911a-10442f7d84b3

Screenshot of Imitate Email personal settings

That's it!