This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

SMTP Error every time i try to send an email
#7
RE: SMTP Error every time i try to send an email
(09-24-2018, 09:50 AM)wormsunited Wrote: I think that sounds amazing! If you can post the code we can update that asap i think in everyone's interest and a major contribution to the community too.

Ok, here's what I changed - and I take no credit for these changes as they are based on code that exists in a php file that doesn't seem to trigger anymore - possibly left over from the ZPanel days?

There are four mail modules, and I decided that whenever an entry is deleted in any of them (mailbox, alias, forwarder or distribution lists) I want to check the database and see if there are any other mailboxes or aliases still using that domain. If not, I want to delete the domain from the Postfix database so Postfix does not use it to route mail to a local mailbox. I don't restart Postfix as I don't think it's necessary (but would be happy if others could confirm this).

The paths I give here are based on the repository paths (e.g. in the sentora-core repository on GitHub, you can go straight into the modules directory, but on my live CentOS servers the path to the modules directory is /etc/sentora/panel/modules).

Mailboxes Module

Edit modules/mailboxes/code/postfix.php and before the final } of the // Deleting PostFix Mailboxes function add:


Code:
   // If no more mailboxes or aliases for the domain exist, delete the domain to
   // prevent Postfix using a local route when sending to this domain in future

   $domaincheck = explode("@", $rowmailbox['mb_address_vc']);
   $sql = $mail_db->prepare("SELECT * FROM mailbox WHERE domain=:domain");
   $sql->bindParam(':domain', $domaincheck[1]);
   $sql->execute();
   $mailboxresult = $sql->fetch();
   $sql = $mail_db->prepare("SELECT * FROM alias WHERE domain=:domain");
   $sql->bindParam(':domain', $domaincheck[1]);
   $sql->execute();
   $aliasresult = $sql->fetch();

   if (!$mailboxresult && !$aliasresult) {
       $sql = $mail_db->prepare("DELETE FROM domain WHERE domain=:domain");
       $sql->bindParam(':domain', $domaincheck[1]);
       $sql->execute();
   }

Aliases Module

Edit modules/aliases/code/postfix.php and before the final } of the // Deleting Postfix Alias function add:


Code:
   // If no more mailboxes or aliases for the domain exist, delete the domain to
   // prevent Postfix using a local route when sending to this domain in future

   $domaincheck = explode("@", $rowalias['al_address_vc']);
   $sql = $mail_db->prepare("SELECT * FROM mailbox WHERE domain=:domain");
   $sql->bindParam(':domain', $domaincheck[1]);
   $sql->execute();
   $mailboxresult = $sql->fetch();
   $sql = $mail_db->prepare("SELECT * FROM alias WHERE domain=:domain");
   $sql->bindParam(':domain', $domaincheck[1]);
   $sql->execute();
   $aliasresult = $sql->fetch();

   if (!$mailboxresult && !$aliasresult) {
       $sql = $mail_db->prepare("DELETE FROM domain WHERE domain=:domain");
       $sql->bindParam(':domain', $domaincheck[1]);
       $sql->execute();
   }

Forwarders Module

Edit modules/forwarders/code/postfix.php, ignore the fact that functions refer to "hmail" instead of "Postfix" (that's left over from Windows when hMailServer was used!) and before the final } of the // Deleting hMail Forwarder function add:


Code:
   // If no more mailboxes or aliases for the domain exist, delete the domain to
   // prevent Postfix using a local route when sending to this domain in future

   $domaincheck = explode("@", $rowforwarder['fw_address_vc']);
   $sql = $mail_db->prepare("SELECT * FROM mailbox WHERE domain=:domain");
   $sql->bindParam(':domain', $domaincheck[1]);
   $sql->execute();
   $mailboxresult = $sql->fetch();
   $sql = $mail_db->prepare("SELECT * FROM alias WHERE domain=:domain");
   $sql->bindParam(':domain', $domaincheck[1]);
   $sql->execute();
   $aliasresult = $sql->fetch();

   if (!$mailboxresult && !$aliasresult) {
       $sql = $mail_db->prepare("DELETE FROM domain WHERE domain=:domain");
       $sql->bindParam(':domain', $domaincheck[1]);
       $sql->execute();
   }

Distribution Lists Module

Edit modules/distlists/code/postfix.php, ignore the fact that "Distubution" is mis-spelt, and before the final } of the // Deleting Postfix Distubution List function add:


Code:
   // If no more mailboxes or aliases for the domain exist, delete the domain to
   // prevent Postfix using a local route when sending to this domain in future

   $domaincheck = explode("@", $rowdl['dl_address_vc']);
   $sql = $mail_db->prepare("SELECT * FROM mailbox WHERE domain=:domain");
   $sql->bindParam(':domain', $domaincheck[1]);
   $sql->execute();
   $mailboxresult = $sql->fetch();
   $sql = $mail_db->prepare("SELECT * FROM alias WHERE domain=:domain");
   $sql->bindParam(':domain', $domaincheck[1]);
   $sql->execute();
   $aliasresult = $sql->fetch();

   if (!$mailboxresult && !$aliasresult) {
       $sql = $mail_db->prepare("DELETE FROM domain WHERE domain=:domain");
       $sql->bindParam(':domain', $domaincheck[1]);
       $sql->execute();
   }

As you can see, it's pretty repetitive but there's a subtle difference for each module in the code, so don't paste the same code into the four files, paste the correct snippet from above into each of the four files and see how it goes for you.

You might also want to do a:

Code:
cp /etc/sentora/panel/modules/xxxxx/code/postfix.php /etc/sentora/panel/modules/xxxxx/code/postfix.php.old

for each file before you make the changes then you will have a backup copy of the original files if the world ends due to the changed code...

Keith
Reply
Thanks given by: TGates , wormsunited


Messages In This Thread
RE: SMTP Error every time i try to send an email - by fearworks - 09-24-2018, 01:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Email has suddenly stopped coming through rsthomas 4 6 ,056 10-12-2022, 09:29 PM
Last Post: rsthomas
user: 'postfix' host: 'localhost' (Got an error reading communication packets) cezars 0 2 ,780 02-01-2022, 08:58 PM
Last Post: cezars
Why can i not send emails from my site phabeon8 3 7 ,540 04-20-2021, 06:29 AM
Last Post: sparkrack

Forum Jump:


Users browsing this thread: 4 Guest(s)