1. 程式人生 > >Sending Email Using Go And Mailgun

Sending Email Using Go And Mailgun

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

  • You'll need a mailgun account with your own verified domains
  • Your Mailgun's Public API Key

Implementation

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
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 <[email protected]>", "Hello", "Testing some Mailgun!", "[email protected]", ) _, id, err := mg.Send(m) return id, err } func main(){ SendSimpleMessage("[email protected]", "key-12345671234567") }
Was This Post Helpful?