Golang SMTP Integration Guide

Minimum code that you need to integrate Mailazy with your Golang application


Prerequisites

You need to complete these given prerequisites, you can skip the step if you have already completed.

  1. Sign up for a Mailazy account.
  2. Complete Domain Authentication.
  3. Generate the Mailazy Access Key

Integrate Mailazy with Golang

Start Sending mail using the code provided below:

package main

import (
	"gopkg.in/gomail.v2"
)

func main() {
	m := gomail.NewMessage()
	m.SetHeader("From", "[email protected]")
	m.SetHeader("To", "[email protected]")
	m.SetHeader("Subject", "Hello!")
	m.AddAlternative("text/html", "Hello <b>Bob</b>!")
	m.AddAlternative("text/plain", "Hello Bob!")

	// Send the email to Bob
	dialer := gomail.NewPlainDialer("devsmtp.mailazy.com", 587, "access_key", "access_secret")
	if err := dialer.DialAndSend(m); err != nil {
		panic(err)
	}
}