Email server not working on Nextcloud despite having the correct settings


I am having an issue with SMTP setup for notification which seem to be common with different fixes. I tried Nextcloud forum and tried the method suggested but I am still not able to resolve it.

Nextcloud Version: Nextcloud Hub II (23.0.6)
Php Version: PHP 7.4.30 (cli)

Php Config:

<?php $CONFIG = array ( 'instanceid' => 'Sensitive Data', 'passwordsalt' => 'Sensitive Data', 'secret' => 'Sensitive Data', 'trusted_domains' => array ( 0 => '', 1 => '', ), 'datadirectory' => '/var/www/html/nextcloud/data', 'dbtype' => 'mysql', 'version' => '', 'overwrite.cli.url' => '', 'dbname' => 'Sensitive Data', 'dbhost' => 'Sensitive Data', 'dbport' => '', 'dbtableprefix' => 'oc_', 'mysql.utf8mb4' => true, 'dbuser' => 'ncadmin', 'dbpassword' => 'Sensitive Data', 'installed' => true, 'maintenance' => false, 'theme' => '', 'loglevel' => 2, 'app_install_overwrite' => array ( 0 => 'caniupdate', 1 => 'flow_notifications', ), 'mail_from_address' => 'nc', 'mail_smtpmode' => 'smtp', 'mail_sendmailmode' => 'smtp', 'mail_domain' => '', 'mail_smtpport' => '25', 'mail_smtpdebug' => true, 'mail_smtphost' => '', ); In the Logging section. I am getting the following error: Swift_TransportException: Connection could not be established with host :stream_socket_client(): unable to connect to (Connection timed out) Log data: ++ Starting Swift_SmtpTransport !! Connection could not be established with host :stream_socket_client(): unable to connect to (Connection timed out) (code: 0) /var/www/html/nextcloud/3rdparty/swiftmailer/swiftmailer/lib/classes/Swift/Events/SimpleEventDispatcher.php - line 138: Swift_Plugins_LoggerPlugin->exceptionThrown() /var/www/html/nextcloud/3rdparty/swiftmailer/swiftmailer/lib/classes/Swift/Events/SimpleEventDispatcher.php - line 116: Swift_Events_SimpleEventDispatcher->bubble() /var/www/html/nextcloud/3rdparty/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php - line 434: Swift_Events_SimpleEventDispatcher->dispatchEvent() /var/www/html/nextcloud/3rdparty/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php - line 145: Swift_Transport_AbstractSmtpTransport->throwException() /var/www/html/nextcloud/3rdparty/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php - line 65: Swift_Transport_AbstractSmtpTransport->start() /var/www/html/nextcloud/lib/private/Mail/Mailer.php - line 204: Swift_Mailer->send() /var/www/html/nextcloud/apps/notifications/lib/MailNotifications.php - line 215: OC\Mail\Mailer->send() /var/www/html/nextcloud/apps/notifications/lib/MailNotifications.php - line 166: OCA\Notifications\MailNotifications->sendEmailToUser() /var/www/html/nextcloud/apps/notifications/lib/BackgroundJob/SendNotificationMails.php - line 49: OCA\Notifications\MailNotifications->sendEmails() /var/www/html/nextcloud/lib/public/BackgroundJob/Job.php - line 79: OCA\Notifications\BackgroundJob\SendNotificationMails->run() /var/www/html/nextcloud/lib/public/BackgroundJob/TimedJob.php - line 95: OCP\BackgroundJob\Job->execute() /var/www/html/nextcloud/cron.php - line 151: OCP\BackgroundJob\TimedJob->execute() The port 25 is definitely open and my smtp provider confirmed the hosted Azure VM is on active list on their side. Completely new Nextcloud and I am looking to get this resolved and not having much luck. Anyone looking at the error message might spot something that I have missed and point it to me. Thanks Raj

Looked up your smtp host setting - is it as simple as should be

Hi Mar,

Thanks for the reply but it is I have double checked with the service


From your server, can you telnet to this address and port 25?

That is interesting. It is timing out


but port 25 is definitely open. There is a ufw rule for it enable

Well… this is going to be an outbound connection. You should not need a ufw rule for it normally. Have you tried it with ufw turned off to rule it out?

If you telnet to port 25 of a typical SMTP server, it should answer in plain text. Otherwise something is getting blocked somewhere.

ISPs typically block port 25, since it is a violation of terms of service to run an email server.

Usually you’ll want to connect via some other port. The submission port of 587 is sometimes used.

See this randomly found tech article on port 587:

If you have a look at’s email settings page:

They specifically show that outgoing mail connections should be via port 587.

So, test that outgoing connections to port 587 work for you…

Here’s what I get:

telnet 587
Connected to
Escape character is '^]'.
220 ESMTP Fastnet Mail Relay Node 1 []
1 Like


you are a legend!!! that seem to have fixed it. I have contacted the smtp service provider to raise a complain on this. They were adamant that no port other than 25 is used, there were no mention of submission port when I asked if there would be anything like this. Learned something new today.

Thank you all. whom helped to resolve this and also help me to understand nextcloud better.