Skip to content

Instantly share code, notes, and snippets.

@remoharsono
Created December 28, 2018 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remoharsono/4c3a3c4704b7d74cfb54e2ed51b88e3a to your computer and use it in GitHub Desktop.
Save remoharsono/4c3a3c4704b7d74cfb54e2ed51b88e3a to your computer and use it in GitHub Desktop.
Send email using via Mailgun API using Go
package main
import (
"fmt"
"log"
mailgun "github.com/mailgun/mailgun-go"
)
var mailgunDomain = "yourdomain.com"
var mailgunAPIKey = "yourAPIKey"
func main() {
mg := mailgun.NewMailgun(mailgunDomain, mailgunAPIKey)
sender := "sender@yourdomain.com"
subject := "Subject here"
body := "Content here"
recipient := "recipient@somedomain.com"
sendMessage(mg, sender, subject, body, recipient)
}
func sendMessage(mg mailgun.Mailgun, sender, subject, body, recipient string) {
message := mg.NewMessage(sender, subject, body, recipient)
resp, id, err := mg.Send(message)
if err != nil {
log.Fatal(err)
}
fmt.Printf("ID: %s Resp: %s\n", id, resp)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment