Skip to content

Commit

Permalink
Create send-email.js
Browse files Browse the repository at this point in the history
Signed-off-by: Raydo Matthee <[email protected]>
  • Loading branch information
burnt-exe authored Jul 28, 2024
1 parent 9e50dd6 commit fa75492
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions events/netlify/functions/send-email.js
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}`,
};
}
};

0 comments on commit fa75492

Please sign in to comment.