{"id":389,"date":"2017-07-28T13:00:00","date_gmt":"2017-07-28T04:00:00","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2017\/07\/28\/golang-ses"},"modified":"2017-07-28T13:00:00","modified_gmt":"2017-07-28T04:00:00","slug":"golang-ses","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2017\/07\/28\/golang-ses\/","title":{"rendered":"AWS SDK\u3092\u4f7f\u3063\u3066Golang\u304b\u3089SES\u7d4c\u7531\u3067\u30e1\u30fc\u30eb\u3092\u9001\u308b"},"content":{"rendered":"

MMM\u30b5\u30fc\u30d0\u30b5\u30a4\u30c9\u30a8\u30f3\u30b8\u30cb\u30a2\u306e\u67f3\u6cbc\u3067\u3059\u3002
\n\u304a\u4e16\u8a71\u306b\u306a\u3063\u3066\u304a\u308a\u307e\u3059\u3002
\n\u590f\u304c\u6765\u307e\u3057\u305f\u304c\u3001\u5317\u6d77\u9053\u306f\u307e\u3060\u304b\u306a\u308a\u6dbc\u3057\u3044\u3067\u3059\u3002<\/p>\n

\u6700\u8fd1Golang\u3092\u4f7f\u3063\u3066Web API\u3092\u30b9\u30af\u30e9\u30c3\u30c1\u958b\u767a\u3057\u3066\u3044\u307e\u3059\u3002
\n\u305d\u3093\u306a\u4e2d\u3067\u3001Amazon SES<\/code> (Simple Email Service) \u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u3092\u9001\u3089\u306a\u3051\u308c\u3070\u3044\u3051\u306a\u3044\u7b87\u6240\u304c\u3042\u308a\u3001\u3084\u308a\u65b9\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n

AWS SDK for Go \u3092\u5c0e\u5165\u3059\u308b<\/h3>\n

\u3044\u3044\u611f\u3058\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u3042\u308c\u3070\u4f7f\u3063\u3066\u3057\u307e\u304a\u3046\u3068\u601d\u3063\u3066\u3044\u305f\u306e\u3067\u3059\u304c\u3001\u3069\u3046\u3084\u3089\u306a\u3055\u305d\u3046(Go\u306f\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u9078\u5b9a\u306b\u60a9\u3080\u3053\u3068\u304c\u591a\u3044\u3067\u3059\u306d\u2026)\u3060\u3063\u305f\u305f\u3081\u3001SDK\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n

\u4eca\u56de\u5fc5\u8981\u306a\u306e\u306fAWS SDK for Go<\/a>\u3067\u3059\u3002
\n\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306f\u666e\u901a\u306b<\/p>\n

$ go get github.com\/aws\/aws-sdk-go\/aws\/...<\/code><\/pre>\n

\u3067\u3082\u3044\u3044\u306e\u3067\u3059\u304c\u3001SES\u3067\u4f7f\u7528\u3059\u308b\u3082\u306e\u3060\u3051\u3067\u5341\u5206\u306a\u305f\u3081\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3057\u305f\u3002<\/p>\n

$ go get github.com\/aws\/aws-sdk-go\/aws\n$ go get github.com\/aws\/aws-sdk-go\/aws\/session\n$ go get github.com\/aws\/aws-sdk-go\/services\/ses<\/code><\/pre>\n

\u3053\u308c\u3067\u3001SES\u3067\u5fc5\u8981\u306a\u30d1\u30c3\u30b1\u30fc\u30b8\u3060\u3051\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n

\u4e8b\u524d\u6e96\u5099<\/h3>\n

\u4eca\u56de\u306f\u4ee5\u4e0b\u306e\u74b0\u5883\u5909\u6570\u304c\u5fc5\u8981\u3067\u3059\u3002\u4e8b\u524d\u306b\u8a2d\u5b9a\u3057\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n

AWS_ACCESS_KEY_ID: AWS\u306e\u30a2\u30af\u30bb\u30b9\u30ad\u30fcID\nAWS_SECRET_KEY: AWS\u306e\u30b7\u30fc\u30af\u30ec\u30c3\u30c8\u30ad\u30fc\nAWS_SES_ENDPOINT: SES\u306e\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u3002\u4ee5\u4e0b\u53c2\u7167\u3002\nAWS_REGION: SES\u306e\u30ea\u30fc\u30b8\u30e7\u30f3\u3002\u4ee5\u4e0b\u53c2\u7167\u3002<\/code><\/pre>\n

\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u3068\u30ea\u30fc\u30b8\u30e7\u30f3\u306f\u3053\u3061\u3089<\/a>\u3092\u898b\u3066\u8a2d\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\n\u4eca\u56de\u306f\u30ea\u30fc\u30b8\u30e7\u30f3\u304c US East (N. Virginia)<\/code> \u3060\u3063\u305f\u305f\u3081\u3001<\/p>\n

AWS_SES_ENDPOINT: email.us-east-1.amazonaws.com\nAWS_REGION: us-east-1<\/code><\/pre>\n

\u3068\u8a2d\u5b9a\u3057\u307e\u3057\u305f\u3002<\/p>\n

\u307e\u305f\u3001SES\u3067verify\u3055\u308c\u3066\u3044\u308b\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3092\u7528\u610f\u3057\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n

\u30b3\u30fc\u30c9<\/h3>\n

SDK\u3067\u306f\u57fa\u672c\u7684\u306b\u3001\u30bb\u30c3\u30b7\u30e7\u30f3\u3092\u4f5c\u3063\u3066\u3001\u30b5\u30fc\u30d3\u30b9\u3092\u4f5c\u3063\u3066\u3001\u30b5\u30fc\u30d3\u30b9\u304b\u3089\u5404\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3059\u3001\u3068\u3044\u3046\u30d5\u30ed\u30fc\u3092\u8e0f\u307f\u307e\u3059\u3002SES\u3067\u3082\u4f8b\u5916\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002
\n\u30bb\u30c3\u30b7\u30e7\u30f3\u306fSDK\u3092\u4f7f\u7528\u3059\u308b\u305f\u3081\u306e\u8a2d\u5b9a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u3088\u3046\u306a\u3082\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u4f5c\u308a\u307e\u3059\u3002<\/p>\n

sess := session.NewSession()<\/code><\/pre>\n

\u305f\u3060\u3057\u3001\u5f15\u6570\u306b *aws.Config{}<\/code> \u3092\u6e21\u3059\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002
\n\u5f15\u6570\u304c\u306a\u3044\u5834\u5408\u306f\u3001\u4e0a\u3067\u5b9a\u7fa9\u3057\u305f\u74b0\u5883\u5909\u6570\u304b\u3089\u5404\u60c5\u5831\u3092\u53d6\u5f97\u3057\u3001\u30bb\u30c3\u30b7\u30e7\u30f3\u304c\u4f5c\u3089\u308c\u307e\u3059\u3002<\/p>\n

\u30b5\u30fc\u30d3\u30b9\u306f\u3001sess\u3092\u4f7f\u3063\u3066\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n

svc := ses.New(sess)<\/code><\/pre>\n

\u6b21\u306b\u3001input\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002input\u3092\u4f5c\u308b\u305f\u3081\u306b\u306f\u6700\u4f4e\u9650\u3001Destination, Message, Source\u304c\u5fc5\u8981\u3067\u3059\u3002
\nDestination\u306f\u3001\u9001\u308a\u5148\u306e\u60c5\u5831,
\nMessage\u306f\u3001title\u3068body,
\nSource\u306f\u9001\u308a\u5143\u306e\u60c5\u5831\u3092\u6301\u3061\u307e\u3059\u3002\u3053\u3061\u3089\u306b\u306f\u3001\u4e0a\u8ff0\u306everify\u6e08\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n

\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u4f5c\u6210\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n

input := &ses.SendEmailInput{\n    Destination: &ses.Destination{\n        ToAddresses: []*string{\n            aws.String("toaddress@example.com"),\n        },\n    },\n    Message: &ses.Message{\n        Body: &ses.Body{\n            Text: &ses.Content{\n                Charset: aws.String("UTF-8"),\n                Data:    aws.String("\u3053\u3053\u306b\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u30dc\u30c7\u30a3\u3092\u57cb\u3081\u8fbc\u3093\u3067\u304f\u3060\u3055\u3044\u3002\n\u3067\u6539\u884c\u304c\u53ef\u80fd\u3067\u3059\u3002"),\n            },\n        },\n        Subject: &ses.Content{\n            Charset: aws.String("UTF-8"),\n            Data:    aws.String("\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u4ef6\u540d"),\n        },\n    },\n    Source:        aws.String("fromaddress@example.com"),\n}<\/code><\/pre>\n

\u3042\u3068\u306f\u3053\u308c\u3092\u3001<\/p>\n

svc.SendEmail(input)<\/code><\/pre>\n

\u306e\u3088\u3046\u306b\u9001\u4fe1\u3057\u307e\u3059\u3002\u5168\u4f53\u306e\u30b3\u30fc\u30c9\u306f\u4ee5\u4e0b\u3067\u3059\u3002<\/p>\n

package main\n\nimport (\n  "errors"\n  "github.com\/aws\/aws-sdk-go\/aws"\n  "github.com\/aws\/aws-sdk-go\/aws\/session"\n  "github.com\/aws\/aws-sdk-go\/service\/ses"\n  "log"\n)\n\nfunc main() {\n    from := "from@example.jp"\n    to := "to@example.jp"\n    title := "\u30e1\u30fc\u30eb\u4ef6\u540d"\n    body := "\u30e1\u30fc\u30eb\u672c\u6587"\n    err := SendEmail(from, to, title, body)\n    if err != nil {\n        log.Println("mail sending error")\n    }\n}\n\nfunc SendEmail(from string, to string, title string, body string) error {\n  svc := ses.New(session.NewSession())\n  input := &ses.SendEmailInput{\n    Destination: &ses.Destination{\n      ToAddresses: []*string{\n        aws.String(to),\n      },\n    },\n    Message: &ses.Message{\n      Body: &ses.Body{\n        Text: &ses.Content{\n          Charset: aws.String("UTF-8"),\n          Data:    aws.String(body),\n        },\n      },\n      Subject: &ses.Content{\n        Charset: aws.String("UTF-8"),\n        Data:    aws.String(title),\n      },\n    },\n    Source: aws.String(from),\n  }\n  _, err := svc.SendEmail(input)\n  if err != nil {\n    return errors.New(err.Error())\n  }\n  return nil\n}<\/code><\/pre>\n

Destination\u306f\u3053\u3061\u3089<\/a>\u306e\u3088\u3046\u306b\u3001CC\u3084BCC\u3092\u5165\u308c\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n

\u307e\u3068\u3081<\/h3>\n

AWS SDK for Go\u3092\u521d\u3081\u3066\u4f7f\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u304c\u30b7\u30f3\u30d7\u30eb\u3067\u4f7f\u3044\u3084\u3059\u304b\u3063\u305f\u3067\u3059\u3002
\n\u4eca\u5f8c\u3082AWS\u3092Go\u304b\u3089\u4f7f\u3063\u3066\u3044\u3053\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

MMM\u30b5\u30fc\u30d0\u30b5\u30a4\u30c9\u30a8\u30f3\u30b8\u30cb\u30a2\u306e\u67f3\u6cbc\u3067\u3059\u3002 \u304a\u4e16\u8a71\u306b\u306a\u3063\u3066\u304a\u308a\u307e\u3059\u3002 \u590f\u304c\u6765\u307e\u3057\u305f\u304c\u3001\u5317\u6d77\u9053\u306f\u307e\u3060\u304b\u306a\u308a\u6dbc\u3057\u3044\u3067\u3059\u3002 \u6700\u8fd1Golang\u3092\u4f7f\u3063\u3066Web API\u3092\u30b9\u30af\u30e9\u30c3\u30c1\u958b\u767a\u3057\u3066\u3044\u307e\u3059\u3002 \u305d\u3093\u306a\u4e2d\u3067\u3001Amazon SES (Simple Email Service) \u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u3092\u9001\u3089\u306a\u3051\u308c\u3070\u3044\u3051\u306a\u3044\u7b87\u6240\u304c\u3042\u308a\u3001\u3084\u308a\u65b9\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002 AWS SDK for Go \u3092\u5c0e\u5165\u3059\u308b \u3044\u3044\u611f\u3058\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u3042 […]<\/p>\n","protected":false},"author":1,"featured_media":826,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[13],"tags":[128,280,264],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/389"}],"collection":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/comments?post=389"}],"version-history":[{"count":0,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/389\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/media\/826"}],"wp:attachment":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/media?parent=389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/categories?post=389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/tags?post=389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}