跳转到主要内容

在本教程中,我将演示如何使用 Go(Lang) 和 mailgun api 发送邮件。 值得庆幸的是,mailgun 的 API 非常棒,一旦您正确设置了所有内容,发送邮件就非常容易。

要求

  • 您需要一个拥有自己经过验证的域的 mailgun 帐户
  • Mailgun 的 Go 包:可从此处下载 > https://github.com/mailgun/mailgun-go
  • Mailgun 的公共 API 密钥

实现

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")

}
文章链接