My new course Building a Production-Ready Service in Go is almost complete - try it out and let me know what you think!

Sending Email Using Go And Mailgun

Elliot Forbes Elliot Forbes ⏰ 1 Minutes 📅 Apr 15, 2017

In this tutorial I'm going to be demonstrating how you can send mail with Go(Lang) and the mailgun api. Thankfully, mailgun's API is fantastic and sending mail is incredibly easy once you've set everything up properly.

Requirements

Implementation

package main

import (
    "github.com/mailgun/mailgun-go"
)

func SendSimpleMessage(domain, apiKey string) (string, error) {
  mg := mailgun.NewMailgun("tutorialedge.net", apiKey, "key-12345671234567")
  m := mg.NewMessage(
    "Excited User <elliot@tutorialedge.net>",
    "Hello",
    "Testing some Mailgun!",
    "elliot@tutorialedge.net",
  )
  _, id, err := mg.Send(m)
  return id, err
}

func main(){
    SendSimpleMessage("postmaster@elliotforbes.co.uk", "key-12345671234567")

}