Skip to main content
We are aware of an issue after updating to cPanel versions 11.110.0.65, 11.126.0.21, or 11.128.0.11, some cPanel plugins or features are no longer functioning properly including WP Toolkit. Please see the following article for more information and updates:
Update to latest cPanel 110, 126, or 128 versions removes "addonfeatures" directory.

Add and remove forwarding emails in shell

Comments

2 comments

  • cPanelLauren
    Hi @Nahoo Thanks for sharing this with everyone! I do want to point out for anyone viewing this that while you're more than welcome to use custom 3rd party scripts/software we do not endorse the use of them and you do so at your own risk. Thanks!
    0
  • Nahoo
    To make it a little more fool-proof, I've added an existence check for the domain... #!/bin/sh ############################################################## # # # QUICK EMAIL FORWARDER # # # # Coded by Noah Hearle, Design Extreme # # https://designextreme.com # # # # Created: 2017/01/23 # # Modified: 2019/06/11 # # # # Usage: sh ./quick_email_forwarder.sh [--delete] # # # ############################################################## ## ARGUMENTS ## alias=$1 delete=$2 ## SETTINGS ## user=somedomain domain=somedomain.com list=/etc/valiases/$domain delete_regex='^[-]*d(elete)?$' email=$alias@$domain email_account=somealias@$domain if [ ! -f "$list" ]; then echo -e "\e[38;5;202mError:\e[0m Domain name '$domain' doesn"t exist in /etc/valiases/" exit fi last_line="$(tail -n 1 $list)" if [ -n "$2" ] && [[ $delete =~ $delete_regex ]]; then if [ "$(grep -c $email $list)" -eq 0 ]; then echo -e "\e[33mWarning:\e[0m Cannot remove $email as it is not found" exit fi sed -i "/$email: $email_account/d" $list echo -e "\e[92mSuccess:\e[0m Removed email: $email" exit fi if [ "$(grep -c $email $list)" -gt 0 ]; then echo -e "\e[33mWarning:\e[0m $email already exists" exit fi sed -i '$ d' $list echo $email: $email_account >> $list sort $list -o $list echo $last_line >> $list chown --from=root.root $user.mail $list echo -e "\e[92mSuccess:\e[0m Added email: $email"
    0

Please sign in to leave a comment.