diff --git a/plugins/auto-domain-grab/index.php b/plugins/auto-domain-grab/index.php index b4bfc5763..9edc7c4e4 100644 --- a/plugins/auto-domain-grab/index.php +++ b/plugins/auto-domain-grab/index.php @@ -36,7 +36,15 @@ class AutoDomainGrabPlugin extends \RainLoop\Plugins\AbstractPlugin if (!empty($aImapCredentials['Host']) && 'auto' === $aImapCredentials['Host']) { $domain = substr(strrchr($oAccount->Email(), "@"), 1); - $aImapCredentials['Host'] = $this->imap_prefix.$domain; + $mxhosts = array(); + if(getmxrr($domain, $mxhosts) && sizeof($mxhosts) > 0) + { + $aImapCredentials['Host'] = $mxhosts[0]; + } + else + { + $aImapCredentials['Host'] = $this->imap_prefix.$domain; + } } } } @@ -55,7 +63,15 @@ class AutoDomainGrabPlugin extends \RainLoop\Plugins\AbstractPlugin if (!empty($aSmtpCredentials['Host']) && 'auto' === $aSmtpCredentials['Host']) { $domain = substr(strrchr($oAccount->Email(), "@"), 1); - $aSmtpCredentials['Host'] = $this->smtp_prefix.$domain; + $mxhosts = array(); + if(getmxrr($domain, $mxhosts) && sizeof($mxhosts) > 0) + { + $aSmtpCredentials['Host'] = $mxhosts[0]; + } + else + { + $aSmtpCredentials['Host'] = $this->smtp_prefix.$domain; + } } } }