Problem with local system email

ditto

Verified User
Joined
Apr 27, 2009
Messages
2,577
When a DirectAdmin account is created,, it also create a default email account that can't be deleted, like this:

[email protected]

The login name for that system email is: DAUSERNAME

Then I setup a "Forwarder" in DirectAdmin for this system email, like this:

[email protected] -> [email protected]

When i send email to [email protected] it is then forwarded correct to the email [email protected]

However when customer use php script to send out email, if that email bounce back then it will bounce back to this address:

[email protected]

The big problem then, is that email that bounce back to [email protected] is NOT forwarded to [email protected]

However if I log into Roundcube with username: DAUSERNAME - then the bounce mail to [email protected] is in the inbox of DAUSERNAME

So the only way I can check if a email is bounce back, is to login to Roundube webmail in the same system email account that I have setup forwarder for. But forwarder only work when email is sent to [email protected] the forwarder does not work when email is sent to [email protected] (wich will happen everythime email bounce back from email sent from a php script).

Also the cron emails will be sent to [email protected] and many users never check that email account in Roundcube.

My suggestion is that DirectAdmin make global change so that every email sent to [email protected] will forward to the user email address listed at this page:

https://SERVER.HOSTNAME.COM:2222/CMD_SHOW_USER?user=USERNAME

That will solve both problems when email is sent from php scripts and bounce back to [email protected]

And it will also solve the problem when users setup cron jobs without stopping cron job from sending email, and then they get tens of thousands of emails in the inbox at [email protected] wich they never know about.

I consider this a big problem.
 
Ive managed to fix this using the idea you proposed.

I had the unroutable address problem adding the server name as domain in DA, so, i ve made a script that after user creation he automatically create a forwarder made like user@serverdomain that point to the user email insert in the user creation.

I would really hope da staff keep this in consideration (and im avaible to provide the easy script im using for that) for fix this issue.

Regards
 
Wow! That sounds great! I would like to wait for a comment from DirectAdmin support. I hope they will look at your script, because that would solve all my daily worrying about this. All users that adds a cron jobs, never care to add code to command to stop email from sending, and nobody check the system email account, and when the cron run every five minutes, that will be a lot of emails over a year or two! Also some users send out email newsletter from Drupal installation using plain php script, and there is always some email address that bounce back, but they never receive thouse bounce mails.

It would be the perfect solution if DirectAdmin would do something based on your script, so that [email protected] always forward mail to the user email insterted in the user creation! I really hope DirectAdmin will do this!

I will wait for DirectAdmin to comment on this. If DirectAdmin don't want to do it, then I would like to pay you for that script if you are willing to share it. But lets wait for DirectAdmin responce. Thanks!
 
Not a national secret ;)

in /usr/local/directadmin/scripts/custom/user_create_post.sh

put
Code:
/usr/local/bin/php /usr/local/directadmin/scripts/custom/add_forwarder.php

and chmod 700 /usr/local/directadmin/scripts/custom/user_create_post.sh

then, in
/usr/local/directadmin/scripts/custom/add_forwarder.php

put
Code:
<?php

include 'httpsocket.php';

$username = $_SERVER[username];
$email = $_SERVER[email];

$sock = new HTTPSocket;
$sock->connect('localhost',2222);

$sock->set_login("admin","PASSWORD");

$sock->set_method('POST');

$sock->query('/CMD_EMAIL_FORWARDERS',
        array(
                'action' => 'create',
                'domain' => 'SERVERNAME',
                'user' => "$username",
                'email' => "$email"
    ));
$result = $sock->fetch_body();

?>

The PHP Class (the socket) can be found here: http://www.directadmin.com/forum/showthread.php?t=258&highlight=httpsocket.php

Also, at admin level you need to add the domain as the servername.

For do that (DA forbid you to do that) you need to edit /usr/local/directadmin/conf/directadmin.conf

Change the line servername= adding a "1" on the server name, restart da, add the domain, restore the directadmin.conf (remove the "1") and restart da again.

At this point you will have the domain (example. server.mynetwork.com) avaible and with those script (edit the password and the servername ofc) you will be able to create the forwarder for each new user created automatically (you need to do manually for the existing user).

Im using this workaround since about 6months or more without issue.

Hope will be useful for you aswell, and, that da take it in consideration for implementation.

Regards
 
PS. Keep in mind that if you change admin password, have to be changed the password in the script aswell or it will stop working.

Regards
 
PPS:

chmod 600 add_forwarder.php httpsocket.php
chown diradmin:diradmin add_forwarder.php httpsocket.php user_create_post.sh

Regards
 
Thank you very much. But I am not sure I dare to try this, because I am afraid of breaking anything. So I hope DirectAdmin support will add this feature, and also make a script to run it for existing users.

I am running DirectAdmin on https using the following in directadmin.conf:

SSL=1
ssl_redirect_host=SERVER.HOSTNAME.COM

And I think ssl will need me to change the code regarding httpsocket.php for that to work.

Also I am afraid of doing the change you mention about:

Change the line servername= adding a "1" on the server name, restart da, add the domain, restore the directadmin.conf (remove the "1") and restart da again.

Also I already have this file: /usr/local/directadmin/scripts/custom/user_create_post.sh with this content:

Code:
#!/bin/bash
mkdir /home/$username/svn_settings
mkdir /home/$username/domains/$domain/svn_repositories
mkdir /home/$username/domains/$domain/svn_settings
svnadmin create /home/$username/domains/$domain/svn_repositories/default
echo "" > /home/$username/domains/$domain/svn_settings/authz
echo "[aliases]" >> /home/$username/domains/$domain/svn_settings/authz
echo "" >> /home/$username/domains/$domain/svn_settings/authz
echo "[groups]" >> /home/$username/domains/$domain/svn_settings/authz
echo "" >> /home/$username/domains/$domain/svn_settings/authz
echo "[/]" >> /home/$username/domains/$domain/svn_settings/authz
echo "$username = r" >> /home/$username/domains/$domain/svn_settings/authz
echo "" >> /home/$username/domains/$domain/svn_settings/authz
echo "[default:/]" >> /home/$username/domains/$domain/svn_settings/authz
echo "$username = rw" >> /home/$username/domains/$domain/svn_settings/authz
htpasswd -cmb /home/$username/svn_settings/passwd $username $passwd >& /dev/null
chown -R apache:apache /home/$username/domains/$domain/svn_repositories
chown -R $username:apache /home/$username/domains/$domain/svn_settings/authz
chown -R $username:apache /home/$username/svn_settings/
exit 0;

So I would need to figure out where in that file to add your code.

I don't dare to test and try this, because my lack of knowledge on the subject. Lets hope DirectAdmin implement it. Please, DirectAdmin!
 
just at the end before exit 0;

Regarding ssl, never tyed honestly but maybe should work.

The servername change is just temporany cause is needed for be able to add the servername as domain in directadmin.

But ok, lets wait da staff, here they will found all the needed info :)

Regards
 
Regarding ssl and httpsocket.php, I think (I am not sure) that if running DirectAdmin on SSL, that I need to change this line in your code:

Code:
$sock->connect('localhost',2222);

To be like this:
Code:
$sock->connect('ssl://localhost', 2222);

But I am not sure.

Regarding adding server hostname as a own domain in DirectAdmin, I feel I do not understand the complications this could create (if any), and therfor don't dare to try it.

I already has a records for the server hostname in dns for my primary domain. I don't have any testserver anymore also. And I am running DirectAdmin multiserver, and I have 3 name servers like tutorial here:

How to add a 3rd name server (ns3): http://help.directadmin.com/item.php?id=196

Yes, lets wait for DirectAdmin reply. Thank you very much.

Edit: I forgot to thank you for information about where to place the line of code in user_create_post.sh, thanks.
 
Last edited:
Regarding the socket honestly dont know, never used ssl with it.

Regarding the hostname as domain the only issue that cause is the "unroutable address" error for mail made as user@domain (thats why ive used to use this workaround, mainly cause i wanted to use hostname as one of the domains).

Regards
 
Regarding ssl and httpsocket.php, I think (I am not sure) that if running DirectAdmin on SSL, that I need to change this line in your code:

Code:
$sock->connect('localhost',2222);

To be like this:
Code:
$sock->connect('ssl://localhost', 2222);

But I am not sure.


This will help http://www.directadmin.com/forum/showthread.php?t=42871

and it should be

PHP:
$sock->connect('127.0.0.1',2222);

after a DA upgrade or use
Code:
ssl_port
 
Create /home/dausername/.forward with


That should work.

Thank you, tested and working. However we need a .forward like that in every user account. So that is my feature request to DirectAdmin support then, that they please make the system add a .forward upon user creation containing the user user personal external email that is added upon account creation.
 
Do you know what line of code I should add in user user_create_post.sh script to achieve this? I would be surprised if it was easy. It would need to make the .forward every time a user account is created, and also to put the user personal external email address in the .forward file. I don't know how to do it, and still this is a feature request to DirectAdmin support. Please add this function.
 
Thank you, tested and working. However we need a .forward like that in every user account. So that is my feature request to DirectAdmin support then, that they please make the system add a .forward upon user creation containing the user user personal external email that is added upon account creation.

I'm sure it's possible to write a script within a minute or two for the purposes


Code:
# cat /usr/local/directadmin/scripts/custom/user_create_post.sh
#!/bin/bash

touch /home/$username/.forward
chown $username:$username /home/$username/.forward
chmod 644 /home/$username/.forward
echo `grep ^email= /usr/local/directadmin/data/users/$username/user.conf  | cut -d \= -f2` > /home/$username/.forward
 
Wow. That was nice of you, zEitEr! As I posted in reply above here http://www.directadmin.com/forum/showthread.php?t=42894&p=217483#post217483 I already have a existing file in /usr/local/directadmin/scripts/custom/user_create_post.sh - do you think I can just add your line of codes at the bottom right before exit 0; line?

I will be away for some hours, but will then test and create new users, and report back here if it works. Thanks!
 
When a DirectAdmin account is created,, it also create a default email account that can't be deleted
To clarify, it isn't DirectAdmin doing this, it's the underlying OS, linux or FreeBSD.

And another clarification, the forwarders for virtual accounts are in addition to the mailboxes; in other words, when you set up a virtual box [email protected] and a forwarder [email protected], the mail will both end up in the mailbox and be forwarded.

But for user email accounts, using a forwarder disables email to the mailbox; it only gets forwarded.

Should the final solution discussed in the thread be implemented in DirectAdmin so it automatically gets done for all new users? I don't know, but I'm inclined to say yes.

Any comments on this?

Jeff
 
Again, thank you zEitEr. I have now been thinking and testing the .forward file. I found one problem, that a .forward file in /home/username/.forward also forward [email protected], and not only [email protected] - so now I am struggling about what to do with existing users. Because some of them might use the system default email daily ([email protected]), and then it will not work but forward instead. I only wanted to forward [email protected]

I must think more about it, maybe I should send a newsletter to all my customer telling them that the default system email address from now on only will be a forwarder. Hmmm?
 
Back
Top