-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Raydo Matthee <[email protected]>
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const nodemailer = require('nodemailer'); | ||
|
||
exports.handler = async function (event, context) { | ||
if (event.httpMethod !== 'POST') { | ||
return { | ||
statusCode: 405, | ||
body: 'Method Not Allowed', | ||
}; | ||
} | ||
|
||
const { name, email } = JSON.parse(event.body); | ||
|
||
// Create a transporter object using the default SMTP transport | ||
let transporter = nodemailer.createTransport({ | ||
host: 'smtp.office365.com', | ||
port: 587, | ||
secure: false, // true for 465, false for other ports | ||
auth: { | ||
user: process.env.EMAIL_USER, // Your Office 365 email address | ||
pass: process.env.EMAIL_PASS, // Your Office 365 email password | ||
}, | ||
}); | ||
|
||
// Set up email data | ||
let mailOptions = { | ||
from: '"Skunkworks" <[email protected]>', | ||
to: '[email protected]', | ||
subject: 'Webinar Registration', | ||
text: `Name: ${name}\nEmail: ${email}`, | ||
html: `<p>Name: ${name}</p><p>Email: ${email}</p>`, | ||
}; | ||
|
||
try { | ||
let info = await transporter.sendMail(mailOptions); | ||
return { | ||
statusCode: 200, | ||
body: 'Registration successful. Thank you!', | ||
}; | ||
} catch (error) { | ||
return { | ||
statusCode: 500, | ||
body: `There was an error sending your registration. Error: ${error.message}`, | ||
}; | ||
} | ||
}; |