contact email + route
This commit is contained in:
parent
3af979bf42
commit
3e4ae8c1df
@ -2,7 +2,7 @@ import { and, desc, eq, not, or, sql } from "drizzle-orm";
|
|||||||
import { db } from "../db/index.js";
|
import { db } from "../db/index.js";
|
||||||
import { authMiddlewareFn } from "../modules/middleware.js";
|
import { authMiddlewareFn } from "../modules/middleware.js";
|
||||||
import { articles, articles as articlesTable, signups as signupsTable, sites, users } from "../db/schemas.js";
|
import { articles, articles as articlesTable, signups as signupsTable, sites, users } from "../db/schemas.js";
|
||||||
import { sendFreebie } from "../utils/email.js";
|
import { sendContactEmail, sendFreebie } from "../utils/email.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -170,5 +170,25 @@ export const blogRoutes = (fastify, _, done) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
fastify.post("/contact", {
|
||||||
|
body: {
|
||||||
|
email: {
|
||||||
|
type: "string",
|
||||||
|
format: "email"
|
||||||
|
},
|
||||||
|
subject: {
|
||||||
|
type: "string"
|
||||||
|
},
|
||||||
|
content: {
|
||||||
|
type: "string"
|
||||||
|
},
|
||||||
|
blog_id: {
|
||||||
|
type: "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, async (req, reply) => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
|
@ -7,18 +7,31 @@ import { MailtrapClient } from "mailtrap";
|
|||||||
const TOKEN = "a0cc97f4f856d6c16d70bb5984e32cef";
|
const TOKEN = "a0cc97f4f856d6c16d70bb5984e32cef";
|
||||||
const ENDPOINT = "https://send.api.mailtrap.io/";
|
const ENDPOINT = "https://send.api.mailtrap.io/";
|
||||||
|
|
||||||
|
const default_sender = {
|
||||||
|
email: "mailtrap@demomailtrap.com",
|
||||||
|
name: "Mailtrap Test",
|
||||||
|
};
|
||||||
|
|
||||||
const client = new MailtrapClient({ endpoint: ENDPOINT, token: TOKEN });
|
const client = new MailtrapClient({ endpoint: ENDPOINT, token: TOKEN });
|
||||||
|
|
||||||
|
export async function sendContactEmail(recipient, sender, subject, body) {
|
||||||
|
client.send({
|
||||||
|
from: default_sender,
|
||||||
|
to: {
|
||||||
|
email: recipient
|
||||||
|
},
|
||||||
|
subject: "Form submission on YouPage.ai",
|
||||||
|
text: `You got a new message from your Youpage.ai page!\nSender: ${sender}\nSubject: ${subject}\nMessage: ${body}`
|
||||||
|
}).catch(console.error);
|
||||||
|
}
|
||||||
|
|
||||||
export async function sendFreebie(recipient, blog_id) {
|
export async function sendFreebie(recipient, blog_id) {
|
||||||
const [blog] = await db.select().from(sites).where(eq(sites.id, blog_id));
|
const [blog] = await db.select().from(sites).where(eq(sites.id, blog_id));
|
||||||
if (!blog) throw new Error("Invalid site");
|
if (!blog) throw new Error("Invalid site");
|
||||||
|
|
||||||
if (!blog.use_freebie || !blog.freebie_url) return;
|
if (!blog.use_freebie || !blog.freebie_url) return;
|
||||||
|
|
||||||
const sender = {
|
const sender = default_sender;
|
||||||
email: "mailtrap@demomailtrap.com",
|
|
||||||
name: "Mailtrap Test",
|
|
||||||
};
|
|
||||||
|
|
||||||
const recipients = [
|
const recipients = [
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user