Skip to content

Commit

Permalink
Add mailer lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejmatu committed May 2, 2018
1 parent 01b3d6f commit 211a33a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ static/admin/*.bundle.*
.DS_Store
yarn-error.log
# lambda functions
functions
functions
.env
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"dependencies": {
"basscss": "^8.0.4",
"concurrently": "^3.5.1",
"dotenv": "^5.0.1",
"gatsby": "^1.9.252",
"gatsby-link": "^1.6.40",
"gatsby-plugin-netlify-cms": "^2.0.1",
Expand All @@ -19,6 +20,7 @@
"lodash": "^4.17.5",
"mongodb": "^3.0.7",
"netlify-cms": "^1.5.0",
"nodemailer": "^4.6.4",
"normalize.css": "^8.0.0",
"prop-types": "^15.6.1",
"react": "^16.3.2",
Expand Down
39 changes: 39 additions & 0 deletions src/lambda/mail-response.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require('dotenv').config();
const nodemailer = require('nodemailer');

exports.handler = function(event, context, callback) {
const user = process.env.MAIL_USER;
const pass = process.env.MAIL_PASSWORD;

let transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 587,
secure: false,
auth: { user, pass }
});

let mailOptions = {
from: `"Maciej 🥝 Smoothielicious" <${user}>`,
to: '[email protected]',
subject: '🍇 Contact submission received!',
text: 'Hello world?',
html: '<b>Hello world?</b>'
};

transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return callback(null, {
statusCode: 500,
body: JSON.stringify(error)
})
}

// console.log('Mail sent to:', mailOptions.to);
console.log(JSON.stringify({ event, context }));

callback(null, {
statusCode: 200,
body: 'mail sent'
})
});
}
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3048,6 +3048,10 @@ dotenv@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-4.0.0.tgz#864ef1379aced55ce6f95debecdce179f7a0cd1d"

dotenv@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-5.0.1.tgz#a5317459bd3d79ab88cff6e44057a6a3fbb1fcef"

download@^4.0.0, download@^4.1.2:
version "4.4.3"
resolved "https://registry.yarnpkg.com/download/-/download-4.4.3.tgz#aa55fdad392d95d4b68e8c2be03e0c2aa21ba9ac"
Expand Down Expand Up @@ -7157,6 +7161,10 @@ [email protected]:
version "1.1.0"
resolved "https://registry.yarnpkg.com/node-version/-/node-version-1.1.0.tgz#f437d7ba407e65e2c4eaef8887b1718ba523d4f0"

nodemailer@^4.6.4:
version "4.6.4"
resolved "https://registry.yarnpkg.com/nodemailer/-/nodemailer-4.6.4.tgz#f0d72d0c6a6ec5f4369fa8f4bf5127a31baa2014"

[email protected]:
version "0.0.0"
resolved "https://registry.yarnpkg.com/noms/-/noms-0.0.0.tgz#da8ebd9f3af9d6760919b27d9cdc8092a7332859"
Expand Down

0 comments on commit 211a33a

Please sign in to comment.