Sending email over SMTP in go is easy. Go contains its own net/smtp package but it can be cumbersome. Luckily there exists the excellent open source emersion go-smtp package. In this post we will show you how to send email using SMTP commands in go.

Install dependencies

Add the dependency to your go project. For this example we will also add MailSlurp to create an SMTP inbox for our test. We can find this at .

Notice the package - we can use that to test our SMTP client code.

Get MailServer connection details

We need to send email with Go to and through email mailservers. We can do this if we know a mailservers port and host names. With MailSlurp we can generate a new disposable mailbox and use the details associated with it.

Sending secure email over TLS

To send email safely with Go we should use TLS secure socket connections. We can do this like so:

How to send when insecure?

If necessary we can also send emails with TLS using an insecure connection: