Email 2FA error: Could not send a verification code via email. An Admin must set this up first

Hello everyone.

I’m trying to configure email two factor authentication for my nextcloud installation at my company. I understand that email isn’t the best option for 2fa security wise, but we must absolutely have it this way so that when a user leaves the company, they can’t access NextCloud anymore until the user is deleted from NextCloud.

However, when I try to set this up with the Two-Factor Email app, I get the following message even tho I’m already using the admin account to set it up:
image
image

Here are the instance details:
-I installed Nextcloud via the AIO method
-Nextcloud version: 24.0.6.1
-Operating System: Linux 5.15.0-1021-gcp x86_64

Here are two Administration>Logging outputs that could be useful:
-[notifications] Error: Swift_TransportException: Connection could not be established with host 127.0.0.1 :stream_socket_client(): Unable to connect to 127.0.0.1:25 (Connection refused) at <>

  1. <>
    Swift_Transport_StreamBuffer->{closure}(“*** sensitive parameters replaced ***”)
  2. /var/www/html/3rdparty/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php line 264
    stream_socket_client(“127.0.0.1:25”, 0, “”, 10, 4, null)
  3. /var/www/html/3rdparty/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php line 58
    Swift_Transport_StreamBuffer->establishSocketConnection()
  4. /var/www/html/3rdparty/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php line 143
    Swift_Transport_StreamBuffer->initialize([“”,“127.0.0.1”, … "])
  5. /var/www/html/3rdparty/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php line 65
    Swift_Transport_AbstractSmtpTransport->start()
  6. /var/www/html/lib/private/Mail/Mailer.php line 195
    Swift_Mailer->send(Swift_Message {}, )
  7. /var/www/html/apps/notifications/lib/MailNotifications.php line 217
    OC\Mail\Mailer->send(OC\Mail\Message {})
  8. /var/www/html/apps/notifications/lib/MailNotifications.php line 168
    OCA\Notifications\MailNotifications->sendEmailToUser(OCA\Notifications\Model\Settings {id: 1}, [OC\Notification … "], “es”, “Europe/Madrid”)
  9. /var/www/html/apps/notifications/lib/BackgroundJob/SendNotificationMails.php line 49
    OCA\Notifications\MailNotifications->sendEmails(500, 1667905373)
  10. /var/www/html/lib/public/BackgroundJob/Job.php line 79
    OCA\Notifications\BackgroundJob\SendNotificationMails->run(null)
  11. /var/www/html/lib/public/BackgroundJob/TimedJob.php line 95
    OCP\BackgroundJob\Job->execute(OC\BackgroundJob\JobList {}, OC\Log {})
  12. /var/www/html/cron.php line 151
    OCP\BackgroundJob\TimedJob->execute(OC\BackgroundJob\JobList {}, OC\Log {})

at 2022-11-08T11:02:53+00:00

-[PHP] Error: Error: Undefined array key “redirect_url” at /var/www/html/core/templates/twofactorsetupselection.php#36 at <>

  1. /var/www/html/core/templates/twofactorsetupselection.php line 36
    OC\Log\ErrorHandler::onError(2, “Undefined array key "redirect_url"”, “/var/www/html/c … p”, 36)
  2. /var/www/html/lib/private/Template/Base.php line 180
    include(“/var/www/html/c … p”)
  3. /var/www/html/lib/private/Template/Base.php line 150
    OC\Template\Base->load(“/var/www/html/c … p”, [[OCA\TwoFactorT … "])
  4. /var/www/html/lib/private/legacy/OC_Template.php line 182
    OC\Template\Base->fetchPage([[OCA\TwoFactorT … "])
  5. /var/www/html/lib/public/AppFramework/Http/TemplateResponse.php line 204
    OC_Template->fetchPage([[OCA\TwoFactorT … "])
  6. /var/www/html/lib/private/AppFramework/Http/Dispatcher.php line 178
    OCP\AppFramework\Http\TemplateResponse->render()
  7. /var/www/html/lib/private/AppFramework/App.php line 172
    OC\AppFramework\Http\Dispatcher->dispatch(OC\Core\Controll … {}, “setupProviders”)
  8. /var/www/html/lib/private/Route/Router.php line 298
    OC\AppFramework\App::main(“OC\Core\Contr … r”, “setupProviders”, OC\AppFramework\ … {}, ["core.TwoFactor … "])
  9. /var/www/html/lib/base.php line 1030
    OC\Route\Router->match(“/login/setupchallenge”)
  10. /var/www/html/index.php line 36
    OC::handleRequest()

GET /login/setupchallenge
from 85.62.55.217 by nasnongadmin at 2022-11-08T10:46:27+00:00

Could not send a verification code via email. An Admin must set this up first

Please make sure that you’ve correctly set-up the email server under “Settings > Management > General > Email Server” . See also Email — Nextcloud latest Administration Manual latest documentation

3 Likes

Solved. I indeed didn’t have an email server configured.

1 Like