Aha! I knew Iād dealt with that problem once last year. I finally found my notes:
=====
NextCloud uses the Horde libraries for the mail app. While I donāt know zilch about PHP I thought I would at least look at the code.
The interesting part is in apps/mail/vendor/pear-pear.horde.org/Horde_Smtp/Horde/Smtp.php.
First there is a function _hello that does the EHLO exchange:
protected function _hello()
{
$ehlo = $host = $this->_getHostname();
if ($host === false) {
$ehlo = $_SERVER['SERVER_ADDR'];
$host = 'localhost';
}
...
We want the function _getHostname:
protected function _getHostname()
{
return ($localhost = $this->getParam('localhost'))
? $localhost
: gethostname();
}
It appears that the PHP builtin gethostname() can only return the non-qualified server host name. So whatās left is the function getParam.
getParam does things to a _params array. That takes us back to the top of the file where there is a constructor filling up a params array. And there is provision for a parameter named localhost. I figured I could play with the array too. So I added a line to force params(ālocalhostā) to contain my fqdn:
public function __construct(array $params = array())
{
// Default values.
$params = array_merge(array(
'chunk_size' => self::CHUNK_DEFAULT,
'context' => array(),
'host' => 'localhost',
'port' => 587,
'secure' => true,
'timeout' => 30,
+ 'localhost' => 'myhostname.example.com'
), array_filter($params));
Save. Try sending. Bingo.
At best thatās a hack, not a fix; Iāll have to edit that file for every upgrade. Also itās a known problem with Horde, although, at first glance, it does not seem to be an issue. Which implies that most SMTP servers out there are configured to accept mail from any host name. And weāre surprised at the prevalence of spam.
=======
Should I file a bug?
Thanks everyone!