Files
formbricks/apps/web/lib/email.ts
Matti Nannt 27d63c01e1 Introducing the new Formbricks (#210)
### New Formbricks Release: Complete Rewrite, New Features & Enhanced UI 🚀

We're thrilled to announce the release of the new Formbricks, a complete overhaul of our codebase, packed with powerful features and an improved user experience.

#### What's New:

1. **Survey Builder**: Design and customize your in-product micro-surveys with our intuitive survey builder.
2. **Trigger Micro-Surveys**: Set up micro-surveys to appear at specific points within your app, allowing you to gather feedback when it matters most.
3. **JavaScript SDK**: Our new JavaScript SDK makes integration a breeze - just embed it once and you're ready to go.
4. **No-Code Events**: Set up events and triggers without writing a single line of code, making it accessible for everyone on your team.
5. **Revamped UI**: Enjoy an entirely new user interface that enhances usability and provides a smooth, delightful experience.

This release marks a major step forward for Formbricks, enabling you to better understand your users and build an outstanding product experience.

Please update your Formbricks integration to take advantage of these exciting new features, and let us know in the Discord if you have any questions or feedback!

Happy surveying! 🎉
2023-03-29 23:34:29 +02:00

114 lines
3.9 KiB
TypeScript

import { withEmailTemplate } from "./email-template";
import { createInviteToken, createToken } from "./jwt";
const nodemailer = require("nodemailer");
interface sendEmailData {
to: string;
replyTo?: string;
subject: string;
text?: string;
html: string;
}
export const sendEmail = async (emailData: sendEmailData) => {
let transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: process.env.SMTP_PORT,
secure: process.env.SMTP_SECURE_ENABLED === "1", // true for 465, false for other ports
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASSWORD,
},
// logger: true,
// debug: true,
});
const emailDefaults = {
from: `Formbricks <${process.env.MAIL_FROM || "noreply@formbricks.com"}>`,
};
await transporter.sendMail({ ...emailDefaults, ...emailData });
};
export const sendVerificationEmail = async (user) => {
const token = createToken(user.id, user.email, {
expiresIn: "1d",
});
const verifyLink = `${process.env.NEXTAUTH_URL}/auth/verify?token=${encodeURIComponent(token)}`;
const verificationRequestLink = `${
process.env.NEXTAUTH_URL
}/auth/verification-requested?email=${encodeURIComponent(user.email)}`;
await sendEmail({
to: user.email,
subject: "Welcome to Formbricks 🤍",
html: withEmailTemplate(`<h1>Welcome!</h1>
To start using Formbricks please verify your email by clicking the button below:<br/><br/>
<a class="button" href="${verifyLink}">Verify email</a><br/>
<br/>
<strong>The link is valid for 24h.</strong><br/><br/>If it has expired please request a new token here:
<a href="${verificationRequestLink}">Request new verification</a><br/>
<br/>
Your Formbricks Team`),
});
};
export const sendForgotPasswordEmail = async (user) => {
const token = createToken(user.id, user.email, {
expiresIn: "1d",
});
const verifyLink = `${process.env.NEXTAUTH_URL}/auth/forgot-password/reset?token=${encodeURIComponent(
token
)}`;
await sendEmail({
to: user.email,
subject: "Reset your Formbricks password",
html: withEmailTemplate(`<h1>Change password</h1>
You have requested a link to change your password. You can do this by clicking the link below:<br/><br/>
<a class="button" href="${verifyLink}">Change password</a><br/>
<br/>
<strong>The link is valid for 24 hours.</strong><br/><br/>If you didn't request this, please ignore this email.<br/>
Your Formbricks Team`),
});
};
export const sendPasswordResetNotifyEmail = async (user) => {
await sendEmail({
to: user.email,
subject: "Your Formbricks password has been changed",
html: withEmailTemplate(`<h1>Password changed</h1>
Your password has been changed successfully.<br/>
<br/>
Your Formbricks Team`),
});
};
export const sendInviteMemberEmail = async (inviteId, inviterName, inviteeName, email) => {
const token = createInviteToken(inviteId, email, {
expiresIn: "7d",
});
// const verifyLink = `${process.env.NEXTAUTH_URL}/api/v1/invite?token=${encodeURIComponent(token)}`;
const verifyLink = `${process.env.NEXTAUTH_URL}/invite?token=${encodeURIComponent(token)}`;
await sendEmail({
to: email,
subject: `You're invited to collaborate on Formbricks!`,
html: withEmailTemplate(`Hey ${inviteeName},<br/><br/>
Your colleague ${inviterName} invited you to join them at Formbricks. To accept the invitation, please click the link below:<br/><br/>
<a class="button" href="${verifyLink}">Join team</a><br/>
<br/>
Have a great day!<br/>
The Formbricks Team!`),
});
};
export const sendInviteAcceptedEmail = async (inviterName, inviteeName, email) => {
await sendEmail({
to: email,
subject: `You've got a new team member!`,
html: withEmailTemplate(`Hey ${inviterName},
<br/><br/>
Just letting you know that ${inviteeName} accepted your invitation. Have fun collaborating!
<br/><br/>
Have a great day!<br/>
The Formbricks Team!`),
});
};