flamewalker
Verified User
- Joined
- Aug 21, 2007
- Messages
- 64
I worked up a script (after many hours of searching and trial and error!) that will set up email accounts listed in a csv file, in the form of:
username,password
This should work well for people like me, who was tasked with migrating email from an old, custom built email server to a DA server. If anyone needs it, I can recode it to import from a list of domains, and a list of emails for each domain.
This script is based off of this:
http://www.directadmin.com/forum/showthread.php?t=14157 , so all due credit to icheck for getting me going!
You must set the domain, script directory, and name the csv list file 'pop_passwd.csv' (in the same directory as the script). Also, set the IP of the DA server, and the username and password of the domain you want to create the emails for.
It is written in perl, so it can easily be run from a command line/ssh shell. Feel free to modify it to your own needs!
Make sure you chmod 755 email-script.pl.
username,password
This should work well for people like me, who was tasked with migrating email from an old, custom built email server to a DA server. If anyone needs it, I can recode it to import from a list of domains, and a list of emails for each domain.
This script is based off of this:
http://www.directadmin.com/forum/showthread.php?t=14157 , so all due credit to icheck for getting me going!
You must set the domain, script directory, and name the csv list file 'pop_passwd.csv' (in the same directory as the script). Also, set the IP of the DA server, and the username and password of the domain you want to create the emails for.
It is written in perl, so it can easily be run from a command line/ssh shell. Feel free to modify it to your own needs!
Code:
#!/usr/bin/perl
#
# poptool.pl
# Create pop accounts from list
#
#
use HTTP::Request::Common qw(GET);
use LWP::UserAgent;
use HTTP::Cookies;
$ua = new LWP::UserAgent;
$ua->cookie_jar(HTTP::Cookies->new);
# Change DOMAIN.COM to users domain name
$domain = "domain.com";
$domain_user = "domain_da_login_user";
$domain_pass = "domain_da_login_pass";
$ip = "server_ip";
#change to dir of this script (I used /home/domain_login_name/script)
$scriptdir = "absolute_script_path";
# This file contains the addresses and plaintext passwords in csv format.
$pop_passwd_text = "$scriptdir/pop_passwd.csv";
#open names file
open(IDFILE, "$pop_passwd_text");
@idfile = <IDFILE>;
close(IDFILE);
foreach $idfile (@idfile) {
chomp $idfile;
$idfile = lc $idfile;
@userpass = split(/,/, $idfile);
$cmd = "CMD_API_POP?action=create\&domain=$domain\&user=$userpass[0]\&passwd=$userpass[1]\"e=0";
$url = "http://$domain_user:$domain_pass\@$ip\:2222/$cmd";
my $req = GET $url;
@results = $ua->request($req)->as_string;
print @results;
}
# end poptool script
Make sure you chmod 755 email-script.pl.