Facing issue with setting up 2fa and email

I was trying to set up 2fa in my kirby instance and getting issue with email setup. I have added the required details including smtp server, username, password, port in config.php but i am still not able to get any code in my email.
Is there something i am missing to setup, the documentation is not that clear on this!

Please help

There are two steps:

  1. You need to enable 2FA in the config: auth | Kirby CMS

  2. You need to set-up email transport

If you have done this, I’d check if sending emails works with your settings, by trying to send an email via the $kirby->email() from a template:

I have done the mentioned steps, although i am not getting how i can check if i can send emails or not?

Here we have the first problem, you may only have one return statement in your config! return returns the script execution to the calling script, hence anything after will not be executed.

Got it, Well now i added those to one return! Still not getting the email to work.

Ok, well, please try to set debugging for authentication like explained here: auth | Kirby CMS

Then check if you get any errors in your php error logs that help to find out what’s going on.

Also, try to send an email according to the email documentation from a template like I suggested above.

On a side note, please copy/paste your code here instead of adding screenshots. Thank you!

Oh, and I found this, maybe it helps: Send Kirby emails with Gmail SMTP and OAuth2

Well i tried to debug the issue, seems like there is some hardcoded invalid email - noreply@<server_ip>

Error Log:
[Mon Sep 18 16:23:17.279596 2023] [php:notice] [pid 51] [client 10.32.15.8:63087] Exception: “noreply@10.36.237.11” is not a valid email address in /var/www/html/kirby/src/Email/Email.php:225\nStack trace:\n#0 /var/www/html/kirby/src/Email/Email.php(306): Kirby\Email\Email->resolveEmail()\n#1 /var/www/html/kirby/src/Toolkit/Properties.php(137): Kirby\Email\Email->setFrom()\n#2 /var/www/html/kirby/src/Toolkit/Properties.php(104): Kirby\Email\Email->setProperty()\n#3 /var/www/html/kirby/src/Email/Email.php(85): Kirby\Email\Email->setProperties()\n#4 /var/www/html/kirby/config/components.php(42): Kirby\Email\Email->__construct()\n#5 /var/www/html/kirby/src/Cms/App.php(617): Kirby\Cms\Core->{closure}()\n#6 /var/www/html/kirby/src/Cms/Auth/EmailChallenge.php(71): Kirby\Cms\App->email()\n#7 /var/www/html/kirby/src/Cms/Auth.php(143): Kirby\Cms\Auth\EmailChallenge::create()\n#8 /var/www/html/kirby/src/Cms/Auth.php(447): Kirby\Cms\Auth->createChallenge()\n#9 /var/www/html/kirby/config/api/routes/auth.php(68): Kirby\Cms\Auth->login2fa()\n#10 [internal function]: Kirby\Cms\Api->{closure}()\n#11 /var/www/html/kirby/src/Api/Api.php(181): Closure->call()\n#12 /var/www/html/kirby/src/Cms/Api.php(46): Kirby\Api\Api->call()\n#13 /var/www/html/kirby/src/Api/Api.php(503): Kirby\Cms\Api->call()\n#14 /var/www/html/kirby/config/routes.php(46): Kirby\Api\Api->render()\n#15 [internal function]: Kirby\Http\Route->{closure}()\n#16 /var/www/html/kirby/src/Http/Router.php(122): Closure->call()\n#17 /var/www/html/kirby/src/Cms/App.php(341): Kirby\Http\Router->call()\n#18 /var/www/html/kirby/src/Cms/App.php(1240): Kirby\Cms\App->call()\n#19 /var/www/html/index.php(5): Kirby\Cms\App->render()\n#20 {main}, referer: http://10.36.237.11:5555/panel/login

The below-mentioned snippet is creating an issue,

$kirby = $user->kirby();
                $kirby->email([
                        'from' => $kirby->option('auth.challenge.email.from', 'noreply@' . $kirby->url('index', true)->host()),
                        'fromName' => $kirby->option('auth.challenge.email.fromName', $kirby->site()->title()),
                        'to' => $user,
                        'subject' => $kirby->option(
                                'auth.challenge.email.subject',
                                I18n::translate('login.email.' . $mode . '.subject', null, $user->language())
                        ),
                        'template' => 'auth/' . $mode,
                        'data' => [
                                'user'    => $user,
                                'site'    => $kirby->system()->title(),
                                'code'    => $formatted,
                                'timeout' => round($options['timeout'] / 60)
                        ]
                ]);

In my case, I am using docker in my private server and accessing the app with IP at port 5555.

Fixed!!

The change i did was from

'from' => $kirby->option('auth.challenge.email.from', 'noreply@' . $kirby->url('index', true)->host()),

to

'from' => $kirby->option('auth.challenge.email.from', 'noreply@yourdomain.com'),

Thanks :slight_smile:

I hope you didn’t change this in the source code?