Skip to content

Commit

Permalink
fix: remove nodemailer for now
Browse files Browse the repository at this point in the history
  • Loading branch information
kizivat committed Aug 10, 2024
1 parent f9b1800 commit ed32eb7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 60 deletions.
19 changes: 0 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"@sveltejs/kit": "^2.5.20",
"@sveltejs/vite-plugin-svelte": "^3.1.1",
"@tailwindcss/typography": "^0.5.10",
"@types/nodemailer": "^6.4.15",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"autoprefixer": "^10.4.15",
Expand Down Expand Up @@ -54,7 +53,6 @@
"formsnap": "^1.0.0",
"lucide-svelte": "^0.379.0",
"mode-watcher": "^0.3.0",
"nodemailer": "^6.9.13",
"stripe": "^15.8.0",
"sveltekit-superforms": "^2.13.1",
"tailwind-merge": "^2.3.0",
Expand Down
69 changes: 30 additions & 39 deletions src/routes/(marketing)/contact/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import {
PRIVATE_NOTIFICATIONS_EMAIL,
PRIVATE_SMTP_HOST,
PRIVATE_SMTP_PASSWORD,
PRIVATE_SMTP_PORT,
PRIVATE_SMTP_USER,
} from '$env/static/private';
import type { PostgrestError } from '@supabase/supabase-js';
import { fail, type Actions, type ServerLoad } from '@sveltejs/kit';
import { createTransport } from 'nodemailer';
import SMTPTransport from 'nodemailer/lib/smtp-transport';
import { message, setError, superValidate } from 'sveltekit-superforms';
import { message, superValidate } from 'sveltekit-superforms';
import { zod } from 'sveltekit-superforms/adapters';
import { formSchema } from './schema';

Expand All @@ -31,15 +22,15 @@ export const actions: Actions = {

const { name, email, subject, body } = form.data;

const transport = createTransport({
host: PRIVATE_SMTP_HOST,
port: Number(PRIVATE_SMTP_PORT),
secure: true,
auth: {
user: PRIVATE_SMTP_USER,
pass: PRIVATE_SMTP_PASSWORD,
},
});
// const transport = createTransport({
// host: PRIVATE_SMTP_HOST,
// port: Number(PRIVATE_SMTP_PORT),
// secure: true,
// auth: {
// user: PRIVATE_SMTP_USER,
// pass: PRIVATE_SMTP_PASSWORD,
// },
// });

const insert = supabaseServiceRole.from('contact_messages').insert({
name,
Expand All @@ -49,18 +40,18 @@ export const actions: Actions = {
updated_at: new Date(),
});

const send = transport.sendMail({
from: `${name} ${PRIVATE_SMTP_USER}`,
to: PRIVATE_NOTIFICATIONS_EMAIL,
subject,
text: `from: ${name} <${email}>\nsubject:${subject}\n\n${body}`,
});
// const send = transport.sendMail({
// from: `${name} ${PRIVATE_SMTP_USER}`,
// to: PRIVATE_NOTIFICATIONS_EMAIL,
// subject,
// text: `from: ${name} <${email}>\nsubject:${subject}\n\n${body}`,
// });

let result: SMTPTransport.SentMessageInfo | null = null,
error: PostgrestError | null = null;
// let result: SMTPTransport.SentMessageInfo | null = null,
let error: PostgrestError | null = null;

try {
[result, { error }] = await Promise.all([send, insert]);
[/*result,*/ { error }] = await Promise.all([/*send, */ insert]);
} catch (e) {
console.warn("Couldn't send contact request email.", e);
if (!error) {
Expand All @@ -80,17 +71,17 @@ export const actions: Actions = {
);
}

if (result && result.rejected.length > 0) {
console.error('Rejected email send response: ', result.response);
console.error(
`Email from ${name} <${email}> with subject ${subject} and body ${body} was rejected.`,
);
return setError(
form,
'',
'An error occured while sending the message. Please try again later.',
);
}
// if (result && result.rejected.length > 0) {
// console.error('Rejected email send response: ', result.response);
// console.error(
// `Email from ${name} <${email}> with subject ${subject} and body ${body} was rejected.`,
// );
// return setError(
// form,
// '',
// 'An error occured while sending the message. Please try again later.',
// );
// }

return message(form, {
success: 'Thank you for your message. We will get back to you soon.',
Expand Down

0 comments on commit ed32eb7

Please sign in to comment.