Email Server credentials not accepted

Getting this error when attempting to validate email server settings:

Details

Nextcloud version (eg, 20.0.5): 28.0.2
Operating system and version (eg, Ubuntu 20.04): Debian GNU/Linux 12 (bookworm)
Apache or nginx version (eg, Apache 2.4.25): Apache/2.4.57 (Debian)
PHP version (eg, 7.4): 8.2.7

The issue you are facing:

Is this the first time you’ve seen this error? (Y/N): Y

Steps to replicate it:

  1. Login as admin, goto Administrator Settings → Basic settings
  2. Enter email server info
  3. Test and verify settings by clicking ‘Send email’

Admin > Logging

Note: These are a few days old, no new entries in log when replicating this issue:

Warning	mail	
Horde_Imap_Client_Exception Too many auth attempts
Could not fetch structure detail data to enhance message previews: Too many auth attempts
Feb 18, 2024, 3:40:02 p.m. 	
Warning	mail	
Horde_Imap_Client_Exception Too many auth attempts
Could not fetch structure detail data to enhance message previews: Too many auth attempts
Feb 18, 2024, 2:35:03 p.m. 	
Error	mail	
Horde_Imap_Client_Exception Mail server denied authentication.
Cron mail sync failed for account 1
Feb 18, 2024, 2:30:34 p.m. 	
Warning	mail	
Horde_Imap_Client_Exception Mail server denied authentication.
Could not fetch structure detail data to enhance message previews: Mail server denied authentication.
Feb 18, 2024, 1:32:36 p.m. 	
Error	PHP	
Error: Class "OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin" not found at /var/www/nextcloud/remote.php#62
Feb 18, 2024, 10:19:12 a.m. 	
Error	mail	
ServiceException Could not set message flag on IMAP: Error when communicating with the mail server.
Could not classify incoming message importance: Could not set message flag on IMAP: Error when communicating with the mail server.
Feb 17, 2024, 1:00:14 p.m. 	
Error	PHP	
Undefined array key 14635 at /var/www/nextcloud/apps/mail/lib/Cache/Cache.php#138
Feb 17, 2024, 10:55:08 a.m. 	
Error	PHP	
Undefined array key 14635 at /var/www/nextcloud/apps/mail/lib/Cache/Cache.php#136
Feb 17, 2024, 10:55:08 a.m. 	
Error	PHP	
Undefined array key 14634 at /var/www/nextcloud/apps/mail/lib/Cache/Cache.php#138
Feb 17, 2024, 10:55:08 a.m. 

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

 <?php
$CONFIG = array (
  'instanceid' => 'oc56j8gtqwmy',
  'passwordsalt' => 'xxxxxxxxxxxxxxxxxxxx',
  'secret' => 'xxxxxxxxxxxxxxxxxxxxx',
  'trusted_domains' =>
  array (
    0 => 'xxxxxxxxx',
  ),
  'trusted_proxies' =>
  array (
    0 => '192.168.1.63',
  ),
  'datadirectory' => '/var/www/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '28.0.2.5',
  'overwrite.cli.url' => 'http://nxxx',
  'dbname' => 'nextcloud_db',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextclouduser',
  'dbpassword' => '9KxxxxJBtyqxd-',
  'installed' => true,
  'default_phone_region' => 'CA',
  'default_locale' => 'en_US',
  'filelocking.enabled' => true,
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'redis' =>
  array (
    'host' => '/var/run/redis/redis-server.sock',
    'port' => 0,
    'timeout' => 0.0,
  ),
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'log_type' => 'file',
  'logfile' => '/var/www/nextcloud/data/nextcloud.log',
  'loglevel' => 2,
  'maintenance_window_start' => 8,
  'maintenance' => false,
  'theme' => '',
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => 'smtp',
  'app_install_overwrite' =>
 array (
    0 => 'files_texteditor',
    1 => 'keeweb',
    2 => 'memories',
  ),
  'updater.release.channel' => 'stable',
  'memories.exiftool' => '/var/www/nextcloud/apps/memories/bin-ext/exiftool-amd64-glibc',
  'memories.vod.path' => '/var/www/nextcloud/apps/memories/bin-ext/go-vod-amd64',
  'enabledPreviewProviders' =>
  array (
    0 => 'OC\\Preview\\Image',
    1 => 'OC\\Preview\\HEIC',
    2 => 'OC\\Preview\\TIFF',
    3 => 'OC\\Preview\\Movie',
  ),
  'mail_from_address' => 'xxxx',
  'mail_domain' => 'ncf.ca',
  'mail_smtphost' => 'mail.ncf.ca',
  'mail_smtpport' => '993',
  'mail_smtpauth' => 1,
  'mail_smtpname' => 'xxxx',
  'mail_smtppassword' => 'xxxx',
  'mail_smtpsecure' => 'ssl',
  'mail_smtpstreamoptions' =>
   array (
     'ssl' =>
     array (
       'allow_self_signed' => true,
       'verify_peer' => false,
       'verify_peer_name' => false,
     ),
   ),
);

That last bit in the config.php file mail_smtpstreamoptions I added today with no changes in the error.

The NC mail app works fine with the same mail credentials. I was also able to setup a mail account wit Microsoft Outlook with the same credentials so it would appear my mail server is accepting my smtp credentials, or should.

Any help appreciated.

Looks like you’re using the wrong port number. Port 993 is normaly used for IMAP over TLS/SSL. Try either port 465 (SSL) or port 587 (None/STARTTLS).

Actually my provider recommends TLS encryption with port 587 for the outgoing server. That seems to work. Thanks for your help. I feel a bit embarrassed…

Just between you and me. I googled it before I replied to make sure I got it right. And after googling it and reading IMAPS, my first thought was: hmm, SSL, IMAPS, looks good, it must be something else, and it was only after scrolling through the logs in your post, googling a few messages and then looking at the screenshot again and googling the port again that I realised: oops! One of the SMTP ports would probably be better suited for sending emails :wink: