Empowering you with the knowledge to master Linux web hosting, DevOps and Cloud

 Linux Web Hosting, DevOps, and Cloud Solutions

Tag: Iredmail. Iredmail free

Removing Domain Aliases in iRedMail: A Simple bash script

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.

Adding Domain Aliases in iRedMail: A Simple bash script

iRedMail is a powerful and open-source mail server solution that simplifies the process of setting up and managing email services. It supports popular email protocols, including IMAP, POP3, and SMTP, and can be used to host multiple email domains. In this guide, we’ll explore how to add domain aliases to iRedMail’s free version with a MySQL backend.

What Are Domain Aliases?
Domain aliases are additional domain names that point to an existing email domain. For example, if you have a primary domain like example.com, you can set up domain aliases like domain.ltd so that emails sent to username@domain.ltd are delivered to the corresponding mailbox of username@example.com. Domain aliases are a convenient way to manage multiple email addresses under a single domain.

The Bash Script:
Here’s a Bash script that simplifies the process of adding domain aliases in iRedMail. You can use this script to automate the task:

#!/bin/bash

# Author: 	Abdul Wahab
# Website: 	Linuxwebhostingsupport.in
# Print purpose and note
printf "Purpose: Add an alias domain in iRedMail. \n\n"
printf "Note: Let's say you have a mail domain example.com hosted on your iRedMail server, if you add domain name domain.ltd as an alias domain of example.com, all emails sent to username@domain.ltd will be delivered to user username@example.com's mailbox. So here domain.ltd is the alias domain and example.com is the traget domain \n\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

# Connect to the vmail database and check if the target domain exists in the domain table
RESULT=`mysql vmail -N -B -e "SELECT COUNT(*) FROM domain WHERE domain='$TARGET_DOMAIN'"`
if [ $RESULT -ne 1 ]
then
  echo "Error: The target domain $TARGET_DOMAIN does not exist in the domain table. You need to add the target domain first"
  exit 1
fi

# Insert the alias domain record
mysql vmail <<EOF
INSERT INTO alias_domain (alias_domain, target_domain)
VALUES ('$ALIAS_DOMAIN', '$TARGET_DOMAIN');
EOF

# Print completion message
echo "Alias domain $ALIAS_DOMAIN has been added for $TARGET_DOMAIN."

How to Use the Script:

Copy the provided Bash script into a text file, e.g., add_domain_alias.sh.
Make the script executable by running the following command:

chmod +x add_domain_alias.sh

Execute the script by running ./add_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 insert the alias domain record.

Conclusion:
Adding domain aliases in iRedMail is a straightforward process, and the provided Bash script can simplify it even further. With domain aliases, you can efficiently manage multiple email addresses under a single domain, enhancing your email hosting capabilities.

Feel free to use this script to streamline your iRedMail email domain management, making it easier to accommodate various email addresses and domains.

Powered by WordPress & Theme by Anders Norén