diff --git a/apps/viewer/pages/api/typebots/[typebotId]/integrations/email.ts b/apps/viewer/pages/api/typebots/[typebotId]/integrations/email.ts index 2bdff9bda..ab29c3792 100644 --- a/apps/viewer/pages/api/typebots/[typebotId]/integrations/email.ts +++ b/apps/viewer/pages/api/typebots/[typebotId]/integrations/email.ts @@ -67,7 +67,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { resultValues: ResultValues fileUrls?: string } - const replyToName = replyTo?.split(' <')[0].replace(/"/g, '') + const { name: replyToName } = parseEmailRecipient(replyTo) const { host, port, isTlsEnabled, username, password, from } = (await getEmailInfo(credentialsId)) ?? {} @@ -191,4 +191,20 @@ const getEmailBody = async ({ } } +const parseEmailRecipient = ( + recipient?: string +): { email?: string; name?: string } => { + if (!recipient) return {} + if (recipient.includes('<')) { + const [name, email] = recipient.split('<') + return { + name: name.replace(/>/g, '').trim().replace(/"/g, ''), + email: email.replace('>', '').trim(), + } + } + return { + email: recipient, + } +} + export default withSentry(handler)