#!/bin/bash

#password reset for a mail box using cPanel api tool

mail="$1";
um=`echo $mail |cut -d "@" -f1`;
ud=`echo $mail |cut -d "@" -f2`;
pw=`openssl rand -base64 12`;
uname=`grep ^$ud: /etc/userdomains |cut -d: -f2 |tr -d " "`;

cpapi2 --user=$uname Email passwdpop domain=$ud  email=$um password=$pw >/dev/null 2>&1

echo;
echo "Password has been reset for $mail to $pw";
echo;
