zamri wrote:
Can you someone give me a php script for creating a new user for dbmail ?

I have this block of code in one of my PHP scripts, it works for me. Anyone care to comment if I'm missing anything?

   function CreateEmailAddress()
   {
       if(strlen($this->new_tocr_email) > 2)
       {
           // First check to see if this address exists already
           $this->new_tocr_email = strtolower($this->new_tocr_email);
$sql = "select user_idnr, userid from dbmail_users where lower(userid) = '$this->new_tocr_email'";
           $res = pg_query($this->db_conn, $sql);
           if (pg_num_rows($res) > 0)
               return 1;

/* The address doesn't exist so keep going. First insert the userid and password */ $res = pg_query($this->db_conn, "insert into dbmail_users (userid,passwd) values ('$this->new_tocr_email', '$this->new_tocr_email')");
           if(pg_result_status($res) != PGSQL_COMMAND_OK)
               return 1;

/* Get the new dbmail_user_idnr and link our record in the people table to it */ $res = pg_query($this->db_conn, "SELECT currval('dbmail_user_idnr_seq'::text) as dbmail_user_idnr");
           $res_obj = pg_fetch_object($res,0);
           $this->dbmail_user_idnr = $res_obj->dbmail_user_idnr;
$res = pg_query($this->db_conn, "update people set dbmail_user_idnr = '$this->dbmail_user_idnr' where id = '$this->id'");
           if(pg_result_status($res) != PGSQL_COMMAND_OK)
               return 1;

           /* Now create an INBOX for the user */
$res = pg_query($this->db_conn, "INSERT INTO dbmail_mailboxes (name, owner_idnr, seen_flag, answered_flag, deleted_flag, flagged_flag, recent_flag, draft_flag, permission) VALUES ('INBOX', '" . $this->dbmail_user_idnr . "', 1, 1, 1, 1, 1, 1, 2)");
           if(pg_result_status($res) != PGSQL_COMMAND_OK)
               return 1;

           /* Now insert all the aliases for this user */
$res = pg_query($this->db_conn, "insert into dbmail_aliases (alias, deliver_to) values ('" . $this->new_tocr_email . "@tocr.com', '$this->dbmail_user_idnr')"); $res = pg_query($this->db_conn, "insert into dbmail_aliases (alias, deliver_to) values ('" . $this->new_tocr_email . "@mail.tocr.com', '$this->dbmail_user_idnr')");
       }
   }

Reply via email to