Skip to content

Instantly share code, notes, and snippets.

@bredmor
Created July 23, 2014 20:09
Show Gist options
  • Save bredmor/594ecec78e99b8ae3988 to your computer and use it in GitHub Desktop.
Save bredmor/594ecec78e99b8ae3988 to your computer and use it in GitHub Desktop.
Automated tool for adding new users to the default mailserver set up following the guide at http://arstechnica.com/information-technology/2014/02/how-to-run-your-own-e-mail-server-with-your-own-domain-part-1/
#!/bin/bash
# Add User to Postfix/Dovecot
echo -n "Enter the new email address: "
read mail_user
echo -n "Enter the new password: "
read mail_pass
echo "Adding User to Postfix Virtual Mailboxes...";
echo -e "$mail_user\t\t$mail_user" >> /etc/postfix/virtual-mailbox-users
echo "Hashing Mailboxes..."
postmap /etc/postfix/virtual-mailbox-users
echo "Adding User to Postfix Virtual Users..."
echo -e "$mail_user\t\t$mail_user" >> /etc/postfix/virtual
echo "Hashing Users..."
postmap /etc/postfix/virtual
echo "Restarting Postfix Service..."
service postfix restart
echo "Generating Password Hash..."
mail_hash=$(doveadm pw -s SSHA512 -p $mail_pass)
echo "Saving Hash to Password DB..."
echo "$mail_user:$mail_hash" >> /etc/dovecot/passwd.db
echo "Restarting Dovecot..."
service dovecot restart
echo "Done."
@Rumple-Phillip
Copy link

Well done. It works pretty well. Would love to see some masking of the password, but other than that, it does what it says on the tin :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment