Created
December 28, 2018 04:59
-
-
Save remoharsono/4c3a3c4704b7d74cfb54e2ed51b88e3a to your computer and use it in GitHub Desktop.
Send email using via Mailgun API using Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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