Posts: 143
Threads: 25
Joined: Aug 2014
Reputation:
4
Sex: Male
Thanks: 46
Given 14 thank(s) in 10 post(s)
SMTP Error every time i try to send an email
09-20-2018, 10:37 AM
Hello guys!
I am trying to fix an issue over the control panel of Sentora and tried many times to search for a solution, either online, either in this forum but without any luck. I hope you guys can help me solve this issue.
So i had an account lets say abc.com in server A and then, i deleted that account from Sentora control panel, created a new server B with the account there. Now if i want to send an email from server A to server B to that domain name i get an error on server A saying this:
Code: SMTP Error: The following recipients failed: email@abc.com: : Recipient address rejected: User unknown in virtual mailbox table
So as you see i get this error, every time i try to send an email.
Any idea how to fix this issue? Thanks in advance guys, any help is much appreciated!
Posts: 208
Threads: 4
Joined: Jun 2018
Reputation:
8
Sex: Male
Thanks: 0
Given 37 thank(s) in 33 post(s)
RE: SMTP Error every time i try to send an email
09-21-2018, 04:17 AM
(09-20-2018, 10:37 AM)wormsunited Wrote: Hello guys!
I am trying to fix an issue over the control panel of Sentora and tried many times to search for a solution, either online, either in this forum but without any luck. I hope you guys can help me solve this issue.
So i had an account lets say abc.com in server A and then, i deleted that account from Sentora control panel, created a new server B with the account there. Now if i want to send an email from server A to server B to that domain name i get an error on server A saying this:
Code: SMTP Error: The following recipients failed: email@abc.com: : Recipient address rejected: User unknown in virtual mailbox table
So as you see i get this error, every time i try to send an email.
Any idea how to fix this issue? Thanks in advance guys, any help is much appreciated!
Hi,
I was looking into this a week or two ago and came to the conclusion that it's something to do with entries remaining in one (or more) of the database tables. IIRC, Postfix is using one of the tables created by Sentora to determine the sending route for emails - if it sees a domain in the table, it thinks it's still local, but then can't find the actual mailbox to send to... or it was something along those lines.
Go to your Sentora database, into the sentora_postfix database, to the domain table and see if you can see the domain that you have now moved away to another server listed. If so, does it have 1 in the active column? If so, try changing it to a 0, then restart the postfix service and see if you can send the mail now.
Keith
Posts: 143
Threads: 25
Joined: Aug 2014
Reputation:
4
Sex: Male
Thanks: 46
Given 14 thank(s) in 10 post(s)
RE: SMTP Error every time i try to send an email
09-21-2018, 08:57 AM
(This post was last modified: 09-21-2018, 09:00 AM by wormsunited.)
(09-21-2018, 04:17 AM)fearworks Wrote: Hi,
I was looking into this a week or two ago and came to the conclusion that it's something to do with entries remaining in one (or more) of the database tables. IIRC, Postfix is using one of the tables created by Sentora to determine the sending route for emails - if it sees a domain in the table, it thinks it's still local, but then can't find the actual mailbox to send to... or it was something along those lines.
Go to your Sentora database, into the sentora_postfix database, to the domain table and see if you can see the domain that you have now moved away to another server listed. If so, does it have 1 in the active column? If so, try changing it to a 0, then restart the postfix service and see if you can send the mail now.
Keith
That solved my issue , changing the value to 0 made it work in charm. I wonder why Sentora does not delete the domain names from the table then. This should be working without any issue, as a basic function. Thanks a million for your information, i got my issue solved and marked your reply as solved too. Hope this can help other members of our community.
Did you checked by deleting the entry too? I mean, makes no sense the entry is there...
Best regards!
Posts: 208
Threads: 4
Joined: Jun 2018
Reputation:
8
Sex: Male
Thanks: 0
Given 37 thank(s) in 33 post(s)
RE: SMTP Error every time i try to send an email
09-21-2018, 12:42 PM
(09-21-2018, 08:57 AM)wormsunited Wrote: That solved my issue , changing the value to 0 made it work in charm. I wonder why Sentora does not delete the domain names from the table then. This should be working without any issue, as a basic function. Thanks a million for your information, i got my issue solved and marked your reply as solved too. Hope this can help other members of our community.
Did you checked by deleting the entry too? I mean, makes no sense the entry is there...
Best regards!
Yeah, when I first tested it I deleted the entry, and can't see any reason why this would do any harm. But then again, I think Sentora keeps quite a few records and marks them as "deleted" in a similar way to above, rather than removing the record, which again I can't see doing any harm. If you were running some sort of mega corporation and were looking to make your database size smaller then I suppose actually deleting the row rather than marking it as inactive would make sense, but in the real world I can't see this being a problem for most people.
Plus, keeping the record also provides a sort of history - there's a plugin (I think it's called ZGod) which still works with Sentora AFAIK, which allows you to view deleted records (for record-keeping, posterity, accounting, etc.) so keeping the rows and marking them as inactive also makes sense for people accessing historical records in this way.
But I agree, this should be taken care of by whichever script does the domain deletion. Perhaps it was an oversight rather than intentional? I will have a look at the code and see if I can spot where it should be slotted in and then update this thread for those who want this "virtual mailbox" error to go away...!
Keith
Posts: 208
Threads: 4
Joined: Jun 2018
Reputation:
8
Sex: Male
Thanks: 0
Given 37 thank(s) in 33 post(s)
RE: SMTP Error every time i try to send an email
09-21-2018, 06:21 PM
It looks like it is better to delete the row from the domain table - as long as you have no need for Postfix to know about it on that server any more. So make sure you have no forwarders, distribution lists, aliases or mailboxes first, and then delete the row rather than changing the active flag to 0.
This is because you might choose to add the domain back into postfix at some future point, by way of adding a new mailbox or alias, for example. If you never deleted it from the database, it won't get added back, so it will be stuck there as an inactive entry and Postfix won't see it (of course, you could manually change the active flag back to 1).
Updating the code is a little complicated, but I have done it on my servers and it seems to be working fine. The complications are mainly to do with how the four mail facilties - mailboxes, aliases, distribution lists and forwarders - all interact with each other and which ones rely on the domain being registered with Postfix. For my setups, I've decided that only the mailboxes and aliases matter, so if no aliases or mailboxes need a domain anymore, it gets deleted. If there's a forwarder set up for a mailbox and the mailbox has gone, it won't work anyway (as the mailbox it relies on has been deleted already) so won't be affected by the loss of the domain, and if there's an alias set up, this is actually recorded as a kind of "hidden" alias anyway, so while that exists the domain won't be deleted.
That probably makes no sense to anyone as it seems really complex and probably over-explained! But the crux is that I think it will work and stop this awkward error when you move email from one Sentora server to another.
If anyone is interested in trying the changes I made, please let me know and I will post code and instructions.
Keith.
Posts: 143
Threads: 25
Joined: Aug 2014
Reputation:
4
Sex: Male
Thanks: 46
Given 14 thank(s) in 10 post(s)
RE: SMTP Error every time i try to send an email
09-24-2018, 09:50 AM
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.
Posts: 208
Threads: 4
Joined: Jun 2018
Reputation:
8
Sex: Male
Thanks: 0
Given 37 thank(s) in 33 post(s)
RE: SMTP Error every time i try to send an email
09-24-2018, 01:50 PM
(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
Posts: 3 ,664
Threads: 241
Joined: May 2014
Reputation:
85
Sex: Male
Thanks: 408
Given 600 thank(s) in 465 post(s)
RE: SMTP Error every time i try to send an email
12-22-2018, 08:02 AM
Ok, looks good to me. It is working good for you on your servers? I'll make the updates and post to master.
Thanks again!
-TGates - Project Council
SEARCH the Forums or read the DOCUMENTATION before posting!
Support Sentora and Donate: HERE
Find my support or modules useful? Donate to TGates HERE
Developers and code testers needed!
Contact TGates for more information
|