Skip to content

Instantly share code, notes, and snippets.

@ryanditjia
Last active May 5, 2021 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanditjia/a21b7824072a21e32685315f2829698e to your computer and use it in GitHub Desktop.
Save ryanditjia/a21b7824072a21e32685315f2829698e to your computer and use it in GitHub Desktop.
Netlify functions (lambda) + form-data + Nodemailer
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 }
@theahmadzai
Copy link

Did you find the solution for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment