Last active
May 5, 2021 19:53
-
-
Save ryanditjia/a21b7824072a21e32685315f2829698e to your computer and use it in GitHub Desktop.
Netlify functions (lambda) + form-data + Nodemailer
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
import parser from 'lambda-multipart-parser' | |
import nodemailer from 'nodemailer' | |
const handler = async (event, context, callback) => { | |
const transporter = nodemailer.createTransport({ | |
host: 'smtp.ethereal.email', | |
port: 587, | |
auth: { | |
user: process.env.ETHEREAL_USER, | |
pass: process.env.ETHEREAL_PASS, | |
}, | |
}) | |
const result = await parser.parse(event) | |
const { name, email, phone, position, files } = result | |
const subject = `[${position}] ${name}` | |
const text = ` | |
Name: ${name}\n | |
Applying for position: ${position}\n | |
Phone: ${phone}\n | |
Email: ${email}\n | |
CV: find attachment\n | |
Cover Letter: find attachment | |
` | |
transporter.sendMail( | |
{ | |
from: 'test-sender@example.com', | |
to: 'hrd@company.com', | |
replyTo: email, | |
subject, | |
text, | |
attachments: files, | |
}, | |
(error, info) => { | |
if (error) { | |
callback(error) | |
} else { | |
callback(null, { | |
statusCode: 200, | |
body: 'Ok', | |
}) | |
} | |
}, | |
) | |
} | |
export { handler } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did you find the solution for this?