iRedMail is a robust and open-source email server solution that simplifies the task of setting up and managing email services. It is designed to handle various email domains efficiently. In this guide, we’ll delve into the process of removing alias domains in iRedMail, using a Bash script to streamline domain management.
Understanding Alias Domains:
Alias domains in iRedMail are additional domain names that point to an existing primary email domain. For example, if you have the primary domain example.com and you’ve set up an alias domain domain.ltd, emails sent to username@domain.ltd will be delivered to the corresponding mailbox of username@example.com. Alias domains are a convenient way to manage multiple email addresses under a single domain umbrella.
The Bash Script:
Here’s a Bash script that makes removing alias domains in iRedMail a breeze. You can use this script to simplify domain management:
#!/bin/bash # Author: Abdul Wahab # Website: Linuxwebhostingsupport.in # Print purpose and note printf "Purpose: Remove an alias domain in iRedMail. \n" # Prompt the user to enter the alias domain name read -p "Enter the alias domain name: " ALIAS_DOMAIN # Prompt the user to enter the target domain name read -p "Enter the target domain name: " TARGET_DOMAIN # Check if the alias and target domains exist in the alias_domain table RESULT=$(mysql -N -s vmail -e "SELECT COUNT(*) FROM alias_domain WHERE alias_domain='$ALIAS_DOMAIN' AND target_domain='$TARGET_DOMAIN';") if [[ "$RESULT" -eq "0" ]]; then echo "Alias domain $ALIAS_DOMAIN for target domain $TARGET_DOMAIN does not exist in the alias_domain table." exit 1 fi # Connect to the vmail database and delete the alias domain record mysql vmail <<EOF DELETE FROM alias_domain WHERE alias_domain='$ALIAS_DOMAIN' AND target_domain='$TARGET_DOMAIN'; EOF # Print completion message echo "Alias domain $ALIAS_DOMAIN for target domain $TARGET_DOMAIN has been removed."
How to Use the Script:
Copy the provided Bash script into a text file, e.g., remove_domain_alias.sh.
Make the script executable by running the following command:
chmod +x remove_domain_alias.sh
Execute the script by running ./remove_domain_alias.sh in your terminal.
Follow the prompts to enter the alias domain and target domain names.
The script will connect to the MySQL database and delete the alias domain record.
Conclusion:
Managing email domains is a critical aspect of running an iRedMail email server. The Bash script provided here simplifies the process of removing alias domains, making it easier to streamline your domain management tasks.
With this script, you can efficiently manage your email domains, ensuring your iRedMail server operates smoothly and meets your email hosting needs.