Automatic POP Accounts

tonimad

New member
Joined
Sep 28, 2009
Messages
2
Hello,

I am looking for a code on the forums but can not find anything too stable, I need some help.

I want to put a registration form on my website, where users can create email accounts (directAdmin pop3 accounts).

Someone is using some nice code that can share?.

waiting your response, regards.
 
Code:
# Change example.com
# Change username
# Change password
# Maybe change 127.0.0.1

use HTTP::Request::Common qw(GET);
use LWP::UserAgent;
use HTTP::Cookies;
$ua = new LWP::UserAgent;
$ua->cookie_jar(HTTP::Cookies->new);

$cmd = "CMD_API_POP?action=create\&domain=example.com\&user=$in{emailaddress}\&passwd=$in{emailpassword}\&quota=0";

$url = "http://username\:password\@127.0.0.1\:2222/$cmd";

my $req = GET $url;

@results = $ua->request($req)->as_string;

chomp(@results);

foreach $results(@results){

        @split = split(/\&/, $results);

        foreach $split(@split){

                ($text,$error) = split(/=/, $split);

                if (($text eq "text")&&($error eq "Unable to create email account")){

                        print "That email account already exists.";

                        last;

                }

        }
}
 
floyd,
did you test this, or is this something you are using?
 
I never post any code unless I have either tested it or am currently using unless I make a note that it is untested.

Now a problem may happen because I have to take out the sensitive information and maybe I took out too much and caused a syntax error.

And my code may not be the best or most efficient. I will be the first to admit that. But it will work. I am completely self taught (if you call books and the internet self taught).

I don't think the cookie_jar line is needed. That portion of code I copy and paste because it works for get and post and when cookies are needed.
 
Last edited:
nothing wrong (I believe) in being self taught, we learn best by experience, so professor, books internet, they have things in common
did try a quick test and it failed lol
might be me, of course, I will continue to play.
might be a stupid idea, but been thinking about offering a free (small) account to draw people to other services
I do have a custom built script for cpanel thou :o
 
Last edited:
If you are using 127.0.0.1 it has to be on the same server and $in{username} and $in{password} have to be form inputs that are passed so therefore you have the parsing code at the top of the script.

Its not a complete code necessarily. Its a snippet for programmers to use and modify for their own use.

Oh and its perl, not php. I know there are a lot of php programmers here.
 
First, thank you very much floyd, for sharing this code.

I'm grateful for your consideration. I've tested the code and is very good, used with post & get from an previus form.

It's interesting to offer some email accounts from my site with a professional touch, and automated.

I want to finish two files:

- get_mailbox.php (The form to collect user data).
- create_mailbox.php (your code to process and create the account).

and share both files in the forum.

Again, thanks for your help.
 
Hi Tonimad

PHP:
<?
include 'httpsocket.php';

$server_ip="111.111.111.111";
$server_login="Username";
$server_pass="Password";
$server_ssl="N";
$domain="mydomain.com";
$quota="10";

$username=$_POST['username'];
$pass=$_POST['pass'];

if (isset($_POST['action']) && $_POST['action'] == "add")
{

echo "Creating e-mail account $username@$domain on the server.... <br>\n";
 
 $sock = new HTTPSocket;
 if ($server_ssl == 'Y')
 {
  $sock->connect("ssl://".$server_ip, 2222);
 }
 else
 { 
  $sock->connect($server_ip, 2222);
 }
 
 $sock->set_login($server_login,$server_pass);
 
 $sock->query('/CMD_API_POP',
     array(
  'action' => 'create',
  'user' => $username,
  'passwd' => $pass,
  'domain' => $domain,
  'quota' => $quota,
     ));
 
 $result = $sock->fetch_parsed_body();
 
 if ($result['error'] != "0")
 {
  echo "<b>Error creating e-Mail $username@$domain on the server:<br>\n";
  echo $result['text']."<br>\n";
  echo $result['details']."<br></b>\n";
 }
 else
 {
  echo "E-mail account $username@$domain (Password: $pass) set correctly on the server.<br>\n";
 }

 exit;
}

?>

<form action="" method="post" name="form1" target="_self" id="form1">
      <table border="0" cellpadding="2">
        <tr>
          <td align="right" valign="middle">Username:</td>
          <td align="center" valign="middle"><label>
            <input name="username" type="text" id="username" size="20" maxlength="12" />
          </label></td>
          <td align="left" valign="middle">@mydomain.com</td>
        </tr>
        <tr>
          <td align="right" valign="middle">Password:</td>
          <td align="center" valign="middle"><label>
            <input name="pass" type="password" id="pass" size="20" maxlength="12" />
          </label></td>
          <td> </td>
        </tr>
        <tr>
          <td> </td>
          <td align="center" valign="middle"><label>
          	<input type=hidden name=action value="add">
            <input type="submit" name="submit" id="submit" value="Submit" />
          </label></td>
          <td> </td>
        </tr>
      </table>
  </form>
 
Back
Top