Created
December 9, 2016 03:31
-
-
Save kevingo/bc24874e778be91093b6411487cbe128 to your computer and use it in GitHub Desktop.
Send mail by SES
This file contains hidden or 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" | |
"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", "[email protected]")) | |
mail.AddTo(RFC5322Format("Gmail 我", "[email protected]")) | |
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) | |
} | |
// Source: http://blog.toomore.net/2015/01/goamz-aws-ses.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment