salesagility / SuiteCRM

SuiteCRM - Open source CRM for the world
https://www.suitecrm.com
GNU Affero General Public License v3.0
4.53k stars 2.1k forks source link

Suite 7.14.1 Inbound Email Cannot be Retrieved #10256

Open maarisk opened 1 year ago

maarisk commented 1 year ago

Inbound e-mails are not retrieved. When user selects in Profile -> Inbound Accounts -> -> Test Connection, user gets error "Can not authenticate to IMAP server: The Auth_SASL package is required for DIGEST-MD5 authentication"

Expected Behavior

User sees inbound e-mails as well as Test Connection returns success.

Actual Behavior

Error message: Can not authenticate to IMAP server: The Auth_SASL package is required for DIGEST-MD5 authentication

Possible Fix

Steps to Reproduce

  1. Go to Profile -> Inbound Accounts and select your account to Edit
  2. Press Test Connection button

or

Go to e-mail inbox.

Context

As a result of this issue, cannot import neither incoming nor outgoing emails into CRM rendering this feature useless.

Your Environment

ckangwei83 commented 1 year ago

Face similar issue. Somehow i notice the imap2 is not working fine. So i am trying to use Native instead. Made changes in file below.

modules/InboundEmail/InboundEmail.php line 8626

protected function getImapHandlerType(): string
{
        global $sugar_config;
        return isset($sugar_config['imap_handler'])?$sugar_config['imap_handler']:'imap2';
 }

By default it will return imap2 and will not trigger native method. So i introduce sugar_config and in the config_override.php to add in $sugar_config['imap_handler'] = 'native';

There are still some issue whereby i am not able to list mailbox folder when doing configuration in inbound email. But i can enter the mailbox myself into the box and the inbound email process scheduler still works.

MaxSprea commented 12 months ago

Hi, I had similar issues and with some trial & error I managed to make the native ImapHandler work.

The main cause of problems is the change in return types of several Imap related functions in PHP>=8.1

For example: imap_open returns an IMAP\Connection instance now (see here) instead of a resource and the functions in the native ImapHandler test for a valid resource (which now returns false).

I had to modify several functions of the ImapHandler to make it work, here are my modifications:

  protected function setStream($stream, $validate = true)
    {
        //if ($validate && !is_resource($stream)) {
        if ($validate && $stream===false) { //stream is no longer a resource
            $this->logger->warn('ImapHandler trying to set a non valid resource az stream.');
        }
        $this->stream = $stream;
    }

    protected function getStream($validate = true)
    {
        //if ($validate && !is_resource($this->stream)) {
        if ($validate && $this->stream===false) { //stream is no longer a resuorce
            $this->logger->warn('ImapHandler trying to use a non valid resource stream.');
        }

        return $this->stream;
    }

    public function close()
    {
        $this->logCall(__FUNCTION__, func_get_args());
        if(imap_is_open($this->getStream())){ //check before closing otherwise imap_close throws an exception
            if (!$ret = imap_close($this->getStream())) {
                $this->log('IMAP close error');
            }
        }
        $this->logReturn(__FUNCTION__, $ret);

        return $ret;
    }

    public function getConnection()
    {
        $this->logCall(__FUNCTION__, func_get_args());
        if($this->getStream()===null){ //must check if stream is null and return false
            $ret=false;
        }
        else{
            $ret = $this->getStream();
        }
        $this->logReturn(__FUNCTION__, $ret);

        return $ret;
    }

    public function ping()
    {
        $this->logCall(__FUNCTION__, func_get_args());
        if($this->getStream()===null){
            $ret = false;
        }
        else{
            $ret = imap_is_open($this->getStream()); //imap_ping has problems and as of php8.2 this new function was introduced
        }
        $this->logReturn(__FUNCTION__, $ret);

        return $ret;
    }

    public function getHeaderInfo($msg_number, $fromLength = 0, $subjectLength = 0, $defaultHost = null)
    {
        $this->logCall(__FUNCTION__, func_get_args());
        $ret = imap_headerinfo($this->getStream(), $msg_number, $fromLength, $subjectLength); //parameter defaultHost removed as of php 8
        if (!$ret) {
            $this->log('IMAP get header info error');
        }
        $this->logReturn(__FUNCTION__, $ret);

        return $ret;
    }

    public function isValidStream($stream): bool
    {
        if(!isset($stream) || $stream===false){
            return false;
        }
        else{
            return true;
        }
        //return is_resource($stream); //stream is not a resource anymore
    }

Note that the imap_is_open function i used in ping() and close() was introduced in PHP 8.2 to solve some issues on the imap_ping function, if you have a previous PHP version it will not work.

Please keep in mind this was a quick hack as I needed to make it work ASAP, take the time to test it and correct any errors before using in a production environment.

These modifications also work on suitecrm 8.4.

meierwitt commented 10 months ago

@MaxSprea In which file did you make the changes? Is it: include/Imap/ImapHandler.php

meierwitt commented 10 months ago

Hello, I have the same problem with SuiteCRM 7.14.2 and PHP 8.2 on a Linux Server with IMAP from netcup.de ISP

meierwitt commented 10 months ago

O.k. - thanks to @MaxSprea and @ckangwei83 - I tested this and it works for me.

Frank

chris001 commented 10 months ago

This needs a PR so Inbound Email will work on PHP 8.1+. Anyone?

maarisk commented 10 months ago

None of the solutions provided here work for me. Switched back to PHP 7.4 due to other issues, but inbound e-mails still don't work and get the same error message.

chris001 commented 10 months ago

The fix is:

pear channel-update pear.php.net
pear install Auth_SASL
sudo systemctl reload apache2  # for linux
sudo systemctl reload php-fpm  # for linux
sudo /opt/bitnami/scripts/apache/reload.sh # for bitnami container

Run these commands on your systems, and report back your results.

MaxSprea commented 10 months ago

The fix is:

pear channel-update pear.php.net
pear install Auth_SASL
sudo systemctl reload apache2  # for linux
sudo systemctl reload php-fpm  # for linux
sudo /opt/bitnami/scripts/apache/reload.sh # for bitnami container

Run these commands on your systems, and report back your results.

Thanks, I can confirm this fixes the issue with most IMAP servers I tried except from Hetzner's where I get this response:

[FATAL] An Imap error detected: "Can not authenticate to IMAP server: A0001 BAD Mate, try AUTHENTICATE \<mechanism>" [FATAL] An Imap error detected: "IMAP open error: Can not authenticate to IMAP server: A0001 BAD Mate, try AUTHENTICATE \<mechanism>" [FATAL] An Imap error detected: "IMAP open error | debug data" [FATAL] An Imap error detected: "ImapHandler:open: {mail.your-server.de:993\/service=imap\/ssl\/tls\/validate->cert\/secure}INBOX" [FATAL] An Imap error detected: "ImapHandler:open: xxxxxxxxxxxxxxxxxxx" [FATAL] An Imap error detected: "ImapHandler:open: password is empty: no" [FATAL] An Imap error detected: "ImapHandler:open: 0" [FATAL] An Imap error detected: "IMAP open error | debug data end "

I will try troubleshooting this as soon as I have some free time as searching for the specific error did not yield any useful solution.

pgorod commented 10 months ago

If this is a matter of installing a component on the server, it's not a SuiteCRM bug - but given that email configuration in SuiteCRM is already more than complex enough, I wonder if a simple PR could be made to just make the situation obvious?

Like print something in the screen or in the logs saying what is missing.

chris001 commented 10 months ago

@MaxSprea Could you ask Hetzner tech support, what exactly does their IMAP server mean by that error message, "A0001 BAD Mate, try AUTHENTICATE <mechanism>"

maarisk commented 8 months ago

The fix is:

pear channel-update pear.php.net
pear install Auth_SASL
sudo systemctl reload apache2  # for linux
sudo systemctl reload php-fpm  # for linux
sudo /opt/bitnami/scripts/apache/reload.sh # for bitnami container

Run these commands on your systems, and report back your results.

With Kerio Connect mailserver this doesn't fix an issue.

Installed packages, channel pear.php.net:

Package Version State Archive_Tar 1.4.14 stable Auth_SASL 1.2.0 stable Console_Getopt 1.4.3 stable PEAR 1.10.13 stable Structures_Graph 1.1.1 stable XML_Util 1.4.5 stable

php.ini points include_path to PEAR package dir.

chris001 commented 8 months ago

@maarisk please paste the text of the error messages coming from your Kerio Connect IMAP server. Also, what's your Security Policy settings on this screen: security-built-into-your-business-email