Skip to content

Instantly share code, notes, and snippets.

@anchoo2kewl
Created August 26, 2014 14:11
Show Gist options
  • Save anchoo2kewl/b90640822258392fe2e6 to your computer and use it in GitHub Desktop.
Save anchoo2kewl/b90640822258392fe2e6 to your computer and use it in GitHub Desktop.
This script helps create a new email account in postfix and dovecot. The domain is hardcoded for my needs because its faster but one may pass the domain as a parameter.
#/bin/bash
# chkconfig: 2345 50 70
SUCCESS=0
FAILURE=1
#
if [ $# -ne 1 ]
then
echo "Usage: createUser {username}"
exit $FAILURE
fi
email="[email protected]"
echo "Enter password for $email:"
# read password twice
read -s -p "Password: " password
echo
read -s -p "Password (again): " password2
# check if passwords match and if not ask again
while [ "$password" != "$password2" ];
do
echo
echo "Please try again!"
read -s -p "Password: " password
echo
read -s -p "Password (again): " password2
done
HASH=$(doveadm pw -s SSHA512 -p$password)
#Add to postfix
echo -e "$email\t $email" >> /etc/postfix/virtual-mailbox-users
echo -e "$email\t$email" >>/etc/postfix/virtual
postmap /etc/postfix/virtual
#DoveCot
echo -e "$email:$HASH" >>/etc/dovecot/passwd.db
#RESTART
service postfix reload
service dovecot restart
echo -e "Email account successfully created"
exit $SUCCESS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment