Last active
September 23, 2017 11:54
-
-
Save arket/ce45cbba4c355c3eb723f196e1f5bf6c to your computer and use it in GitHub Desktop.
lambdaでSESメール送信
This file contains 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
var awsSdk = require('aws-sdk'); | |
var libmime = require('libmime'); | |
exports.handler = (event, context, callback) => { | |
var ses = new awsSdk.SES({ | |
apiVersion: '2010-12-01', | |
region: 'SESのリージョン' | |
}); | |
// 送信先 | |
var to = ['送信先メールアドレス']; | |
// 送信元 | |
var from = '送信者メールアドレス'; | |
// 送信者名 | |
var fromName = '私がメールを送ったマン'; | |
// 送信者名 MIMEエンコード | |
fromName = libmime.encodeWord(fromName, 'Q'); | |
from = fromName + ' <' + from + '>'; | |
// 件名 | |
var subject = 'メールタイトル'; | |
// 本文 | |
var body = '本文です。'; | |
// SES 送信用 パラメータ | |
var params = { | |
Destination: { | |
ToAddresses: to | |
}, | |
Message: { | |
Body: { | |
Text: { | |
Data: body, | |
Charset: 'iso-2022-jp' | |
} | |
}, | |
Subject: { | |
Data: subject, | |
Charset: 'iso-2022-jp' | |
} | |
}, | |
Source: from | |
}; | |
var email = ses.sendEmail(params, function(err, data){ | |
if(!err) { | |
// 成功 | |
callback(null, data); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment