import { json } from '@sveltejs/kit';
import { render } from 'svelte-email';
import { Resend } from 'resend';
import { RESEND_API_KEY } from '$env/static/private';
import MailTemplate from './MailTemplate.svelte';
const resend = new Resend( RESEND_API_KEY );
export const POST = async ({request}) => {
const body = await request.json()
console.log(body);
const {invoiceEmail,invoiceCustomer,invoice} = body;
const html = render({
template: MailTemplate,
props: {
firstName: invoiceCustomer,
invoiceEmail: invoiceEmail,
invoiceCustomer: invoiceCustomer,
invoice:invoice
}
})
try {
resend.emails.send({
from: 'Notifications FOS <notifications@fos.kubeira.com>',
to: invoiceEmail,
subject: 'Hello '+ invoiceCustomer,
html: html
});
console.log('Email sent successfully');
} catch (error) {
console.log('There was an error sending the mail',error);
}
return json({status:201,message: 'Email sent'})
}
import { json } from '@sveltejs/kit';
import { render } from 'svelte-email';
import { Resend } from 'resend';
import { RESEND_API_KEY } from '$env/static/private';
import MailTemplate from './MailTemplate.svelte';
const resend = new Resend( RESEND_API_KEY );
export const POST = async ({request}) => {
const body = await request.json()
console.log(body);
const {invoiceEmail,invoiceCustomer,invoice} = body;
const html = render({
template: MailTemplate,
props: {
firstName: invoiceCustomer,
invoiceEmail: invoiceEmail,
invoiceCustomer: invoiceCustomer,
invoice:invoice
}
})
try {
resend.emails.send({
from: 'Notifications FOS <notifications@fos.kubeira.com>',
to: invoiceEmail,
subject: 'Hello '+ invoiceCustomer,
html: html
});
console.log('Email sent successfully');
} catch (error) {
console.log('There was an error sending the mail',error);
}
return json({status:201,message: 'Email sent'})
}