Repository: appwrite/appwrite
File: app/controllers/api/account.php (PHP)

Code before:
                        if (!empty($customTemplate['replyTo'])) {
                            $replyTo = $customTemplate['replyTo'];
                        }

                        $body = $customTemplate['message'] ?? '';
                        $subject = $customTemplate['subject'] ?? $subject;
                    }

                    $queueForMails
                        ->setSmtpReplyTo($replyTo)
                        ->setSmtpSenderEmail($senderEmail)
                        ->setSmtpSenderName($senderName);
                }

                $emailVariables = [
                    'direction' => $locale->getText('settings.direction'),
                    // {{user}}, {{project}} and {{otp}} are required in the templates
                    'user' => $user->getAttribute('name'),
                    'project' => $project->getAttribute('name'),
                    'otp' => $code,
                    'agentDevice' => $agentDevice['deviceBrand'] ?? $agentDevice['deviceBrand'] ?? 'UNKNOWN',
                    'agentClient' => $agentClient['clientName'] ?? 'UNKNOWN',
                    'agentOs' => $agentOs['osName'] ?? 'UNKNOWN',
                ];

                if ($smtpBaseTemplate === 'email-base-styled') {
                    $emailVariables = array_merge($emailVariables, [
                        'heading' => $heading,
                        'accentColor' => APP_EMAIL_ACCENT_COLOR,
                        'logoUrl' => APP_EMAIL_LOGO_URL,
                        'twitterUrl' => APP_SOCIAL_TWITTER,
                        'discordUrl' => APP_SOCIAL_DISCORD,
                        'githubUrl' => APP_SOCIAL_GITHUB_APPWRITE,
                        'termsUrl' => APP_EMAIL_TERMS_URL,
                        'privacyUrl' => APP_EMAIL_PRIVACY_URL,
                    ]);
                }

                $queueForMails
                    ->setSubject($subject)
                    ->setPreview($preview)
                    ->setBody($body)
                    ->setBodyTemplate($bodyTemplate)
                    ->setVariables($emailVariables)
                    ->setRecipient($user->getAttribute('email'))
                    ->trigger();
                break;
        }

        $queueForEvents
            ->setParam('userId', $user->getId())

Review comment (suggestion):
Lets global search all places where we trigger job for queueForEmails. Lets make sure we have those additions in all places (use of smtpBaseTemplate, and addition of those variables)

You can probably prompt AI agent too

Code after:
                $subject = $locale->getText("emails.mfaChallenge.subject");
                $preview = $locale->getText("emails.mfaChallenge.preview");
                $heading = $locale->getText("emails.mfaChallenge.heading");

                $customTemplate = $project->getAttribute('templates', [])['email.mfaChallenge-' . $locale->default] ?? [];
                $smtpBaseTemplate = $project->getAttribute('smtpBaseTemplate', 'email-base');

                $validator = new FileName();
                if (!$validator->isValid($smtpBaseTemplate)) {
                    throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Invalid template path');
                }

                $bodyTemplate = __DIR__ . '/../../config/locale/templates/' . $smtpBaseTemplate . '.tpl';

                $detector = new Detector($request->getUserAgent('UNKNOWN'));
                $agentOs = $detector->getOS();
                $agentClient = $detector->getClient();
                $agentDevice = $detector->getDevice();

                $message = Template::fromFile(__DIR__ . '/../../config/locale/templates/email-mfa-challenge.tpl');
                $message
                    ->setParam('{{hello}}', $locale->getText("emails.mfaChallenge.hello"))
                    ->setParam('{{description}}', $locale->getText("emails.mfaChallenge.description"))
                    ->setParam('{{clientInfo}}', $locale->getText("emails.mfaChallenge.clientInfo"))
                    ->setParam('{{thanks}}', $locale->getText("emails.mfaChallenge.thanks"))
                    ->setParam('{{signature}}', $locale->getText("emails.mfaChallenge.signature"));

                $body = $message->render();

                $smtp = $project->getAttribute('smtp', []);
                $smtpEnabled = $smtp['enabled'] ?? false;

                $senderEmail = System::getEnv('_APP_SYSTEM_EMAIL_ADDRESS', APP_EMAIL_TEAM);
                $senderName = System::getEnv('_APP_SYSTEM_EMAIL_NAME', APP_NAME . ' Server');
                $replyTo = "";

                if ($smtpEnabled) {
                    if (!empty($smtp['senderEmail'])) {
                        $senderEmail = $smtp['senderEmail'];
                    }
                    if (!empty($smtp['senderName'])) {
                        $senderName = $smtp['senderName'];
                    }
                    if (!empty($smtp['replyTo'])) {
                        $replyTo = $smtp['replyTo'];
                    }

                    $queueForMails
                        ->setSmtpHost($smtp['host'] ?? '')
                        ->setSmtpPort($smtp['port'] ?? '')
                        ->setSmtpUsername($smtp['username'] ?? '')