Have a look at the ispconfig sources how ISPConfig creates email accounts. Generally add the correct records in the database tables isp_isp_user, isp_node and isp_dep and set the run file.
It is a bit complicated, thats why we created the remoting framework. Make a new ISPConfig installation, create a email account and compare the database tables I mentioned above with the empty database you had before to get a idea what ISPConfig is doing.