Skip to content

Instantly share code, notes, and snippets.

@kurosuke
Created May 25, 2014 13:40
Show Gist options
  • Save kurosuke/03fdcf49d9d1bf56dec7 to your computer and use it in GitHub Desktop.
Save kurosuke/03fdcf49d9d1bf56dec7 to your computer and use it in GitHub Desktop.
#!/bin/sh
domain=sample.com
maildir_path=/var/vhosts
new_user=$1
password=$2
if [ "$password" = "" ]; then
echo Usage: $0 user password
exit 1
fi
mailaddr=${new_user}@${domain}
#
# for postfix
#
cd /etc/postfix
echo ${new_user}@${domain} ${domain}/${new_user}/Maildir/ >> vmailbox
sudo -u vhosts mkdir $maildir_path/${domain}/${new_user}
sudo -u vhosts maildirmake $maildir_path/${domain}/${new_user}/Maildir
echo ${password} | saslpasswd2 -p -u ${domain} -c ${new_user} -n
# reload conf
postmap vmailbox
service postfix reload
#
# for dovecot
#
cd /etc/dovecot
digest=`doveadm pw -s DIGEST-MD5 -u ${mailaddr} -p ${password}`
echo ${mailaddr}:$digest >> users
chown vhosts:vhosts users
service dovecot reload
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment