使用 curl 批量向 iredmail 提交新邮箱用户和密码

需求:iredmail 免费版没有 api,除了官方带的工具外,有没其它方法可以批量创建账号呢?

尝试:可以使用 curl 来提交表单,用脚本循环提交。

##
# Configurations.
##

read -p "请输入iredmain管理台的登录网址URL,如 https://mail.anqun.org/iredadmin/login: " login_url
read -p "请输入iredmail的创建用户网址URL,如 https://mail.anqun.org/iredadmin/create/user: " create_url
read -p "请输入邮局的管理员用户名,如 postmaster@lan.anqun.org: " username
read -p "请输入邮局的管理员用密码: " password

read -p "请输入要添加用户的域名,如 lan.anqun.org: " domainname
read -p "请输入要添加用户的个数,如 100: " number

rm iredmail-users.txt
rm tmpcs.txt
rm cookie

# Path to temporary file which will store your cookie data.
cookie_path=cookie

action_url="$create_url/$domainname"

##
# Logic. Most likely you shouldn't change here anything.
##

curl -i -b $cookie_path -c $cookie_path -d "username=$username&password=$password" "$login_url"

curl -i -b $cookie_path -c $cookie_path -o tmpcs.txt --request GET "$action_url"

csrf_token=$(grep -oP '(?<=<input type="hidden" name="csrf_token" value=")[^"]*' tmpcs.txt)


for ((i=1; i<=$number; i++))
    do
        mailuser=$(strings /dev/urandom |tr -dc a-z0-9 | head -c8)
        mailpasswd=$(strings /dev/urandom |tr -dc a-z0-9 | head -c8)
        echo $mailuser@$domainname  $mailpasswd >> iredmail-users.txt

        data="csrf_token=$csrf_token&domainName=$domainname&username=$mailuser&newpw=$mailpasswd&confirmpw=$mailpasswd&cn=&preferredLanguage=en_US&mailQuota=1024&submit_add_user=Add"
        curl -i --cookie cookie --data "${data}" "$action_url"
done

参考:https://www.drupal.org/node/2045751

标签: iredmail, curl, bash

添加新评论