import {serverConfig} from "../serverConfig"; import nodemailer from 'nodemailer'; export default function createInvitationEmail(data: any, options: any = {}) { return sendEmail(data, { provider: { transport: serverConfig.transport, from: serverConfig.from, }, ...options }); } const sendEmail = (invitation: any, { provider, }) => new Promise( (resolve, reject) => { const { transport, from } = provider; nodemailer.createTransport(transport).sendMail( { from: `Calendso <${from}>`, to: invitation.toEmail, subject: ( invitation.from ? invitation.from + ' invited you' : 'You have been invited' ) + ` to join ${invitation.teamName}`, html: html(invitation), text: text(invitation), }, (error) => { if (error) { console.error("SEND_INVITATION_NOTIFICATION_ERROR", invitation.toEmail, error); return reject(new Error(error)); } return resolve(); }); }); const html = (invitation: any) => { let url: string = process.env.BASE_URL + "/settings/teams"; if (invitation.token) { url = `${process.env.BASE_URL}/auth/signup?token=${invitation.token}&callbackUrl=${url}`; } return `
Hi,

` + (invitation.from ? invitation.from + ' invited you' : 'You have been invited' ) + ` to join the team "${invitation.teamName}" in Calendso.


If you prefer not to use "${invitation.toEmail}" as your Calendso email or already have a Calendso account, please request another invitation to that email.
`; } // just strip all HTML and convert
to \n const text = (evt: any) => html(evt).replace('
', "\n").replace(/<[^>]+>/g, '');