Skip to content

Instantly share code, notes, and snippets.

@toomore
Last active August 29, 2015 14:14
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 toomore/1ea2b4db44458097abfe to your computer and use it in GitHub Desktop.
Save toomore/1ea2b4db44458097abfe to your computer and use it in GitHub Desktop.
goamz ses first try.
package main
import (
"fmt"
"net/mail"
"github.com/goamz/goamz/aws"
"github.com/goamz/goamz/exp/ses"
//"github.com/kr/pretty"
)
const (
AccessKey string = "..."
SecretKey string = "..."
)
func RFC5322Format(nick, email string) string {
result := mail.Address{Name: nick, Address: email}
return result.String()
}
func main() {
auth := aws.Auth{
AccessKey: AccessKey,
SecretKey: SecretKey,
}
sesapi := ses.NewSES(auth, aws.USEast)
//fmt.Printf("sesapi: %# v", pretty.Formatter(sesapi))
fmt.Println(sesapi)
mail := ses.NewEmail()
mail.SetSource(RFC5322Format("我.me", "me@toomore.net"))
mail.AddTo(RFC5322Format("Gmail 我", "toomore0929@gmail.com"))
message := ses.Message{
Body: ses.Body{Html: ses.Content{Data: "Toomore <b>測試</b>", Charset: "UTF-8"}},
Subject: ses.Content{Data: "Test from goamz 測試中文", Charset: "UTF-8"},
}
mail.SetMessage(message)
//fmt.Printf("mail: %# v", pretty.Formatter(mail))
err := sesapi.SendEmail(mail)
fmt.Println("send: ", err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment