
postwwwacct hook.
In this guide, you’ll learn how to automatically create email accounts (like info@domain.com) immediately after a hosting account is created, even when provisioning via WHMCS.
⚙️ What Is postwwwacct?
postwwwacct is a script hook that runs right after a new cPanel account is created.
This allows you to:
- Run custom automation
- Configure services
- Create email accounts automatically
🎯 What We’re Building
We will:
- Detect newly created cPanel account
- Extract username and domain
- Automatically create an email account
- Log all actions for debugging
📜 The Script
Here is the working production-ready script:
#!/bin/bash
LOGFILE="/root/email_hook.log"
echo "===== $(date) =====" >> $LOGFILE
echo "ARGS: $@" >> $LOGFILE
# Parse arguments (key value pairs)
while [[ $# -gt 0 ]]; do
key="$1"
value="$2"
case $key in
user)
USER="$value"
shift 2
;;
domain)
DOMAIN="$value"
shift 2
;;
*)
shift
;;
esac
done
echo "Parsed USER=$USER DOMAIN=$DOMAIN" >> $LOGFILE
# Validate
if [[ -z "$USER" || -z "$DOMAIN" ]]; then
echo "Invalid parameters, skipping..." >> $LOGFILE
exit 1
fi
# Wait for mail system ready
sleep 10
# Create email
/usr/bin/uapi --user="$USER" Email add_pop \
email=info \
password='StrongP@ssword123!' \
quota=1024 >> $LOGFILE 2>&1
echo "Done for $USER ($DOMAIN)" >> $LOGFILE
📂 Installation
- Save the script to:
- Make it executable:
🔍 How It Works
When a new account is created:
- WHM triggers the script
- Script reads system arguments
- Extracts:
- Username
- Domain
- Waits for mail service readiness
- Creates email using
uapi - Logs everything
📊 Log File
All activity is logged here:
Example output:
status: 1
Done for john (example.com)
⚠️ Common Pitfalls (Important!)
❌ Wrong Argument Parsing
cPanel does NOT pass arguments like:
👉 This script correctly handles that format.
❌ Email Not Created via WHMCS
If you’re using WHMCS, this script still works—but only if:
- Hook executes correctly
- Mail services are ready
❌ Timing Issues
Sometimes mail services aren’t ready instantly.
Fix:
🔐 Security Improvement (Recommended)
Avoid hardcoded passwords.Instead, generate dynamically:
🧩 Advanced Customization
Create Multiple Emails
/usr/bin/uapi –user=“$USER“ Email add_pop \
email=$EMAIL \
password=‘StrongP@ssword123!’ \
quota=1024
done
Prevent Duplicate Emails
🧠 Why This Matters
Automation like this:
- Saves time
- Reduces human error
- Improves customer onboarding
- Scales your hosting business
✅ Final Result
After setup, every new hosting account will automatically have:
Ready to use—without manual setup.
🏁 Conclusion
Using postwwwacct with cPanel is a simple yet powerful way to automate email provisioning.
Whether you’re running a hosting business or managing multiple servers, this method ensures consistency and efficiency.
