diff --git a/packages/api/package.json b/packages/api/package.json index 23d509a8f..f08a9a8ab 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -86,6 +86,7 @@ "luxon": "^3.2.1", "nanoid": "^3.1.25", "node-html-markdown": "^1.3.0", + "node-mailjet": "^6.0.5", "nodemailer": "^6.7.3", "normalize-url": "^6.1.0", "oauth": "^0.10.0", diff --git a/packages/api/src/services/send_emails.ts b/packages/api/src/services/send_emails.ts index 279b193f9..4d6a76bb2 100644 --- a/packages/api/src/services/send_emails.ts +++ b/packages/api/src/services/send_emails.ts @@ -1,6 +1,8 @@ import { env } from '../env' import { generateVerificationToken } from '../utils/auth' +import { logger } from '../utils/logger' import { sendEmail } from '../utils/sendEmail' +import mailjet from 'node-mailjet' export const sendConfirmationEmail = async (user: { id: string @@ -16,6 +18,10 @@ export const sendConfirmationEmail = async (user: { link, } + if (process.env.USE_MAILJET) { + return sendWithMailJet(user.email, link) + } + return sendEmail({ from: env.sender.message, to: user.email, @@ -24,6 +30,44 @@ export const sendConfirmationEmail = async (user: { }) } +const sendWithMailJet = async ( + email: string, + link: string +): Promise => { + if (!process.env.MAILJET_API_KEY || !process.env.MAILGET_SECRET_KEY) { + return false + } + + const client = mailjet.apiConnect( + process.env.MAILJET_API_KEY, + process.env.MAILGET_SECRET_KEY + ) + + try { + const request = await client.post('send', { version: 'v3.1' }).request({ + Messages: [ + { + From: { + Email: 'no-reply@omnivore.app', + }, + To: [ + { + Email: email, + Name: 'Omnivore', + }, + ], + Subject: 'Your Omnivore verification link', + TextPart: `Your Omnivore verification link ${link}`, + }, + ], + }) + } catch (err) { + logger.error('error sending with mailjet', { err }) + return false + } + return true +} + export const sendVerificationEmail = async (user: { id: string name: string diff --git a/packages/web/components/templates/auth/EmailSignup.tsx b/packages/web/components/templates/auth/EmailSignup.tsx index f45afb793..1f920f7ba 100644 --- a/packages/web/components/templates/auth/EmailSignup.tsx +++ b/packages/web/components/templates/auth/EmailSignup.tsx @@ -46,185 +46,174 @@ export function EmailSignup(): JSX.Element { ) return ( - - - We have temporarily suspended signup via email while we work to resolve - an issue with our email provider. - - - - Join our discord for more information - - - - //
- // - // - // Sign Up - // - // - // - // Email - // { - // e.preventDefault() - // setEmail(e.target.value) - // }} - // required - // /> - // + + + + Sign Up + + + + Email + { + e.preventDefault() + setEmail(e.target.value) + }} + required + /> + - // - // Password - // setPassword(e.target.value)} - // required - // /> - // + + Password + setPassword(e.target.value)} + required + /> + - // - // Full Name - // setFullname(e.target.value)} - // required - // /> - // + + Full Name + setFullname(e.target.value)} + required + /> + - // - // Username - // - // - // {username && username.length > 0 && usernameErrorMessage && ( - // - // {usernameErrorMessage} - // - // )} - // {isUsernameValid && ( - // - // Username is available. - // - // )} - // + + Username + + + {username && username.length > 0 && usernameErrorMessage && ( + + {usernameErrorMessage} + + )} + {isUsernameValid && ( + + Username is available. + + )} + - // {errorMessage && {errorMessage}} + {errorMessage && {errorMessage}} - // - // Omnivore will send you daily tips for your first week as a new user. - // If you don't like them you can unsubscribe. - // + + Omnivore will send you daily tips for your first week as a new user. + If you don't like them you can unsubscribe. + - // - // - // - // + + + + - // - // Already have an account?{' '} - // - // - // Login instead - // - // - // - // - // - // + + Already have an account?{' '} + + + Login instead + + + + +
+ ) }