Problem with automating email forwarder during account creation

glarkin

Verified User
Joined
Apr 27, 2004
Messages
24
Hi there,

I've starting working with the various custom scripts that are invoked when domain or users are created and destroyed. This is a great feature!

What I'm trying to do is create a forwarder on each new account with the address "postmaster@<domain>". This address will forward to the email address entered on the "Create a User" page.

To do this, I created the script user_create_post.sh and verified that it is called. From what I can see, there is no API for creating an email forwarder yet, so I just use this curl command in my script:

/usr/local/bin/curl -u $username:$passwd -d "action=create&create=Create&domain=$domain&user=$username&email=$email" http://mysubdomain.domain.com:2222/CMD_EMAIL_FORWARDER

This command is invoked correctly, but if I redirect the output of the command to a temp file, I see these messages in it:

Unable to determine Usertype
user.conf needs to be repaired


However, I can run the command manually at the command line after the new account has been created in DA. Is there some kind of race condition where I cannot do certain things through the DA API until the function that has called my script is completely done? Is there any other way to do what I want?

Thank you,
Greg Larkin
 
I'd just sneak behind DA, and go directly to the file:

Code:
#!/bin/sh

echo "postmaster: $username" >> /etc/virtual/$domain/aliases

exit 0;
Much simpler :D

As long as you are using the "post" script, DA should be done with the file.

John
 
Hi John,

Thanks for the tip, that helped a lot. I just implemented something similar, but I added the postmaster alias to the top of the aliases file. It looked like adding it to the bottom might mess up the catch-all rule, but I could be wrong. Here's the code:


# Save a backup of the aliases
cp -a /etc/virtual/$domain/aliases /etc/virtual/$domain/aliases.bak

# Place the new alias at the top of the file so we don't break the
# catch-all rule.
echo "postmaster: $email" > /etc/virtual/$domain/aliases
cat /etc/virtual/$domain/aliases.bak >> /etc/virtual/$domain/aliases


I checked the list of the forwarders in DA afterward, and the postmaster alias shows up there.

Thanks again,
Greg
 
Back
Top