hitesh
September 18, 2023, 12:26pm
1
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
texnixe
September 18, 2023, 12:36pm
2
There are two steps:
You need to enable 2FA in the config: auth | Kirby CMS
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:
hitesh
September 18, 2023, 12:54pm
3
texnixe:
$kirby->email()
I have done the mentioned steps, although i am not getting how i can check if i can send emails or not?
texnixe
September 18, 2023, 1:22pm
4
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.
hitesh
September 18, 2023, 1:35pm
5
Got it, Well now i added those to one return! Still not getting the email to work.
texnixe
September 18, 2023, 1:47pm
6
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!
texnixe
September 18, 2023, 1:53pm
7
hitesh
September 18, 2023, 2:32pm
8
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.
hitesh
September 18, 2023, 2:36pm
9
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
texnixe
September 18, 2023, 2:37pm
10
I hope you didn’t change this in the source code?
texnixe
Split this topic
November 3, 2023, 4:55pm
11
aba3aba
November 23, 2023, 5:12pm
12
Hey @hitesh !
I am building a user signup for a project using also gmail. I have added the configuration with the same type, host and port, with my username and password but I doesn’t seem to work in my case. I am just testing with a simple email from the Kirby tutorial but it days it was not possible to connect to smtp server, did you have to configure something on your google account?
texnixe
November 23, 2023, 7:51pm
13
aba3aba
November 24, 2023, 12:59pm
14
Thank you for sharing.
Yes, I had a look before arriving to this post, but the approach taken here seemed more simple since it was not integrating OAuth to connect to the Gmail SMTP server but perhaps I am missing a part in the configuration and it is actually needed?
My idea is to use a Gmail from a Google Workspace account to send the codes for users to login to a specific page in the website.