Issue with mail from address when sending link password to owner

When “Send password by mail” is disabled and “Enforce password protection” is enabled, nextcloud sends an automatically generated password to the link owner. In this case, the from address is the to the owners email address. In all other cases (that I know of), the from address from Basic settings - Email server is used. The latter is correct, while using the owner mail address is not possible. We use an external mail server with authentication, nextcloud logs in as nextcloud@ and tries to send as @

Nextcloud version 16.0.3 / 16.0.4
OS: CentOS 7
Apache 2.4
PHP 7.2

Steps to replicate it:

  1. configure mail settings, external mail server with authentication in basic settings
  2. settings, sharing, disable “Send password by mail”, enable “Enforce password protection”
  3. share by mail, error: "Expected response code 354 but got code “554”, with message “554 5.5.1 Error: no valid recipients”

Of couse, this only happens if the mail server verifies if the authenticated user is using a correct from address.


protected function sendPassword

$message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]);

protected function sendPasswordToOwner

if ($initiatorEMailAddress) {
$message->setFrom([$initiatorEMailAddress => $initiatorDisplayName]);