summaryrefslogtreecommitdiff
path: root/src/routes/contact/submit.js
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-01-07 01:32:15 -0700
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-01-07 01:32:15 -0700
commitb09e1e603287c5a29e336c0d4f2df8f28ef769a2 (patch)
tree5d6567ef17ba864e1f7df92b10b47f398f814089 /src/routes/contact/submit.js
parentdb671d26c43e47b8285d319a0fd758df60d729c7 (diff)
downloadmistymountainstherapy-b09e1e603287c5a29e336c0d4f2df8f28ef769a2.tar.gz
mistymountainstherapy-b09e1e603287c5a29e336c0d4f2df8f28ef769a2.zip
make the text pretty
Diffstat (limited to 'src/routes/contact/submit.js')
-rw-r--r--src/routes/contact/submit.js64
1 files changed, 56 insertions, 8 deletions
diff --git a/src/routes/contact/submit.js b/src/routes/contact/submit.js
index 24f4559..9fa00ab 100644
--- a/src/routes/contact/submit.js
+++ b/src/routes/contact/submit.js
@@ -1,10 +1,54 @@
import 'dotenv/config';
-import { EnvMistyMountainsMailerFactory } from '$lib/utils';
+import * as nodemailer from 'nodemailer';
+import { continueRetryUntilValidation } from '$lib/utils';
+
+class MistyMountainsMailer {
+ constructor(username, password, from, domain, port) {
+ this.from = from;
+ this.username = username;
+ this.password = password;
+ this.domain = domain;
+ this.port = port;
+
+ this.transporter = nodemailer.createTransport({
+ host: this.domain,
+ port: this.port,
+ auth: {
+ user: this.username,
+ pass: this.password
+ },
+ requireTLS: true,
+ tls: {
+ rejectUnauthorized: true
+ }
+ });
+ }
+
+ async sendMail(to, subject, message) {
+ const mail = {
+ from: this.from,
+ subject,
+ html: message,
+ to
+ };
+
+ return !!(await continueRetryUntilValidation(async () => {
+ const { messageId } = await this.transporter.sendMail(mail);
+ return messageId;
+ }));
+ }
+}
export async function post({ request }) {
const body = await request.json();
const { HCAPTCHA_SECRET, FORM_TO_EMAIL } = process.env;
- const mailer = EnvMistyMountainsMailerFactory();
+ const mailer = new MistyMountainsMailer(
+ process.env.SMTP_USERNAME,
+ process.env.SMTP_PASSWORD,
+ process.env.FROM_EMAIL,
+ process.env.SMTP_SERVER,
+ Number(process.env.SMTP_PORT)
+ );
const captchaVerified = await fetch(
`https://hcaptcha.com/siteverify?response=${body.captchaToken}&secret=${HCAPTCHA_SECRET}`,
@@ -25,14 +69,18 @@ export async function post({ request }) {
};
}
- const text = `Name: ${body.name}
-Phone Number: ${body.phone || 'Not Given'}
-Email: ${body.email}
-Message: ${body.message}
-`;
+ const text = `<h1>new MMT message</h1>
+<p>Name: ${body.name}</p>
+<p>Phone Number: ${body.phone || 'Not Given'}</p>
+<p>Email: ${body.email}</p>
+<hr>
+<br>
+<p>${body.message}</p>
+<br>
+<p>brought to you by <a href="https://github.com/Simponic/mistymountains">simponic</a></p>`;
const messageSent = await mailer
- .sendMail(FORM_TO_EMAIL, `Form Submission from ${body.name}`, text)
+ .sendMail(FORM_TO_EMAIL, `New Message From ${body.name}`, text)
.then(() => true)
.catch((error) => {
console.error(error);