Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const sendEmail = require('./sendEmail')
- module.handles = async (event, context) => {
- const body = JSON.parse(event.body)
- const { name, email, budget, message, attachment } = body
- if (!name) {
- return {
- statusCode: 400,
- body: JSON.stringify({ message: 'Name is required' }),
- }
- }
- if (!email) {
- return {
- statusCode: 400,
- body: JSON.stringify({ message: 'Email address is required' }),
- }
- }
- if (!message) {
- return {
- statusCode: 400,
- body: JSON.stringify({ message: 'Message is required' }),
- }
- }
- return Promise.all([
- sendEmail({
- to: 'Example <user@example.com>',
- subject: 'Received submission',
- data:
- 'Hello'
- }),
- sendEmail({
- to: `${name} <${email}>`,
- subject: 'Subject',
- data:
- 'Example text',
- })
- ]).then(res=>{
- console.log('worked')
- return {
- statusCode: 200,
- headers: {
- 'Access-Control-Allow-Origin': '*',
- 'Access-Control-Allow-Credentials': true,
- },
- body: JSON.stringify({ message: 'Great success' })
- };
- }).catch(err=>{
- console.error(err);
- return {
- statusCode: 500,
- body: JSON.stringify({
- message: "Oh no :( Message not delivered",
- error: err,
- })
- };
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement