Configure fqdn for nextcloud host

My mail server is configured to reject mail from hosts with no FQDN. The default configuration of the Mail App only uses the base host name, therefore I cannot send mail from NextCloud.

How do I configure the FQDN for the mail app?

Thanks in advance.
Philippe

Using an intermediary MTA that fix the problem?
For example a local postfix server that act as a relay server.

Possible! Although thatā€™s using a F-18 to shoot down a fly.

Iā€™d be better off installing a webmail server!

Iā€™m looking for a one linerā€¦

1 Like

:smiley: Iā€™m stealing that for later use

@tflidd any idea? Else ping the Mail app devs.

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!

Please do file a bug :slight_smile:

Done. #6325.