Sharebymail error: Swift_TransportException: Expected response code 250 but got code 550

Nextcloud version: 21.0.4
Operating system and version: debian 10
Apache version: 2.4.38
PHP version: 7.3.29

When sharing a file by mail I got the following error:

Error: Swift_TransportException: Expected response code 250 but got code “550”, with message "550 Request failed; Mailbox unavailable

Here is the full error log:

[no app in context] Error: OC\HintException: Failed to send share by mail at <>

  1. /var/www/nextcloud/apps/sharebymail/lib/ShareByMailProvider.php line 185
    OCA\ShareByMail\ShareByMailProvider->createMailShare(OC\Share20\Share {})
  2. /var/www/nextcloud/lib/private/Share20/Manager.php line 806
    OCA\ShareByMail\ShareByMailProvider->create(OC\Share20\Share {})
  3. /var/www/nextcloud/apps/files_sharing/lib/Controller/ShareAPIController.php line 632
    OC\Share20\Manager->createShare(OC\Share20\Share {})
  4. /var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php line 218
    OCA\Files_Sharing\Controller\ShareAPIController->createShare(OC\Files\Node\File {}, 17, 4, “w***@gmail.com”, “false”, “”, null, “”, “”)
  5. /var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php line 127
    OC\AppFramework\Http\Dispatcher->executeController(OCA\Files_Sharin … {}, “createShare”)
  6. /var/www/nextcloud/lib/private/AppFramework/App.php line 157
    OC\AppFramework\Http\Dispatcher->dispatch(OCA\Files_Sharin … {}, “createShare”)
  7. /var/www/nextcloud/lib/private/Route/Router.php line 302
    OC\AppFramework\App::main(“OCA\Files_Shar … r”, “createShare”, OC\AppFramework\ … {}, {_route: "ocs.fi … "})
  8. /var/www/nextcloud/ocs/v1.php line 63
    OC\Route\Router->match("/ocsapp/apps/fi … s")
  9. /var/www/nextcloud/ocs/v2.php line 24
    require_once("/var/www/nextcloud/ocs/v1.php")

POST /ocs/v2.php/apps/files_sharing/api/v1/shares
from 194.xxx.xxx.xxx by w*** at 2021-08-24T08:18:51+00:00

[sharebymail] Error: Swift_TransportException: Expected response code 250 but got code “550”, with message "550 Request failed; Mailbox unavailable
" at <>

  1. /var/www/nextcloud/3rdparty/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php line 345
    Swift_Transport_AbstractSmtpTransport->assertResponseCode(“550 Request fai … n”, [250])
  2. /var/www/nextcloud/3rdparty/swiftmailer/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php line 305
    Swift_Transport_AbstractSmtpTransport->executeCommand("\r\n.\r\n", [250], , false, null)
  3. /var/www/nextcloud/3rdparty/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php line 407
    Swift_Transport_EsmtpTransport->executeCommand("\r\n.\r\n", [250])
  4. /var/www/nextcloud/3rdparty/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php line 503
    Swift_Transport_AbstractSmtpTransport->streamMessage(Swift_Message {})
  5. /var/www/nextcloud/3rdparty/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php line 519
    Swift_Transport_AbstractSmtpTransport->doMailTransaction(Swift_Message {}, “w***@aol.com”, [“w***@gmail.com”], )
  6. /var/www/nextcloud/3rdparty/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php line 206
    Swift_Transport_AbstractSmtpTransport->sendTo(Swift_Message {}, “w***@aol.com”, {w***@gmail.com: null}, )
  7. /var/www/nextcloud/3rdparty/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php line 71
    Swift_Transport_AbstractSmtpTransport->send(Swift_Message {}, )
  8. /var/www/nextcloud/lib/private/Mail/Mailer.php line 205
    Swift_Mailer->send(Swift_Message {}, )
  9. /var/www/nextcloud/apps/sharebymail/lib/ShareByMailProvider.php line 423
    OC\Mail\Mailer->send(OC\Mail\Message {})
  10. /var/www/nextcloud/apps/sharebymail/lib/ShareByMailProvider.php line 336
    OCA\ShareByMail\ShareByMailProvider->sendMailNotification(“doc.xlsx”, “https://cloud. … K”, “w***”, “w***@gmail.com”, null)
  11. /var/www/nextcloud/apps/sharebymail/lib/ShareByMailProvider.php line 185
    OCA\ShareByMail\ShareByMailProvider->createMailShare(OC\Share20\Share {})
  12. /var/www/nextcloud/lib/private/Share20/Manager.php line 806
    OCA\ShareByMail\ShareByMailProvider->create(OC\Share20\Share {})
  13. /var/www/nextcloud/apps/files_sharing/lib/Controller/ShareAPIController.php line 632
    OC\Share20\Manager->createShare(OC\Share20\Share {})
  14. /var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php line 218
    OCA\Files_Sharing\Controller\ShareAPIController->createShare(OC\Files\Node\File {}, 17, 4, “w***@gmail.com”, “false”, “”, null, “”, “”)
  15. /var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php line 127
    OC\AppFramework\Http\Dispatcher->executeController(OCA\Files_Sharin … {}, “createShare”)
  16. /var/www/nextcloud/lib/private/AppFramework/App.php line 157
    OC\AppFramework\Http\Dispatcher->dispatch(OCA\Files_Sharin … {}, “createShare”)
  17. /var/www/nextcloud/lib/private/Route/Router.php line 302
    OC\AppFramework\App::main(“OCA\Files_Shar … r”, “createShare”, OC\AppFramework\ … {}, {_route: "ocs.fi … "})
  18. /var/www/nextcloud/ocs/v1.php line 63
    OC\Route\Router->match("/ocsapp/apps/fi … s")
  19. /var/www/nextcloud/ocs/v2.php line 24
    require_once("/var/www/nextcloud/ocs/v1.php")

POST /ocs/v2.php/apps/files_sharing/api/v1/shares
from 194.xxx.xxx.xxx by w*** at 2021-08-24T08:18:51+00:00

I’m able to sent test mails & also through other apps (e.g. polls) but not with sharebymail.

Here are the mail setting in my config.php:

‘mail_from_address’ => ‘w***’,
‘mail_smtpmode’ => ‘smtp’,
‘mail_domain’ => ‘aol.com’,
‘mail_smtpauth’ => 1,
‘mail_smtpsecure’ => ‘tls’,
‘mail_smtpname’ => ‘w***’,
‘mail_smtppassword’ => ‘***’,
‘mail_smtpport’ => ‘587’,

I’ve seen a similar forum post but that user did have problems with invitation mails whereas I’m having problems sending mails from sharebymail. I’ve tested other online webmail providers (gmx.de, yahoo, gmail) & other smtp ports / encryption methods but all with the same result.

What could be the cause?

I’ve solved this by using sendmail instead of SMTP
Now my config looks like:

‘mail_from_address’ => ‘w*****’,
‘mail_smtpmode’ => ‘sendmail’,
‘mail_domain’ => ‘aol.com’,

Postfix was already configured for another application (openmediavault) and it seems sendmail is using theses settings.
So, problem solved without too much hassle.

I’ve finally found the cull print of this error: when using Sharebymail there is an extra Reply-To header added with the email addres of the Nextcloud user. Free mail services like Yahoo & AOL cannot find the mailbox of that user hence the 550 error.

So when you use postfix this problem can easily be solved by replacing these Reply-To headers with the mailaddres your Nextcloud instance is using to send out mails. The only downside is that when a user replies to this kind of mails (which rarely occurs imo), the mail is send to the Nextcloud mailbox instead of the mailbox of the user who is sharing the file. A small downside if you ask me.

So in postfix you need to perform these 2 steps:

Add this line to /etc/postfix/main.cfg

sender_canonical_maps = regexp:/etc/postfix/sender_canonical

Then create this file and add the following line:

/.+/ <mailaddres of your nextcloud instance>

And restart the postfix service. From now one Sharebymail will work!