Create a user by email
Email integration is a powerful feature of DeepDesk. It allows to insert into the system any kind of entity with a simple and fast configuration.
Usually, email integration is used to create Service Operations that represents the requests made by the customers via email.
It is possibile, using a dedicated mailbox, also to create users in the system.
Think about an automatic system implemented on an external application that sends formatted emails every time a user registers to the company site (or e-commerce).
By creating users that way we can provide automatically an account to the support portal DeepDesk.
To configure a mailbox select the grid IN from the menu System > Tools > Email > Mailbox.
Follow the settings of the screenshot above, changing host, user and password with the data of your mailbox.
The most important configuration to create users is then the System Data Tab.
Using this setting we can tell the system that every email read by that mailbox will generate an entity inside DeepDesk and we can also tell the data to fill the fields of that record.
Note: the field Outgoing Mailbox is not relevant for this guide, it is usually set to define the mailbox used to answer by the Service module.
The following data are the entry point to link an email to an entity of DeepDesk.
The field “Model” is the entity (the table of the database) of DeepDesk.
The Model Field and the Prefix will be used together to parse the email subject.
In few words, the field Prefix is a string used to tell DeepDesk: “Hey, after this string you will find a unique field of the record”. That unique field is the Model Field.
DeepDesk uses an internal algorithm and knows that has to read that specific field and if the value is inside the DB that record will be updated. If not, a new record will be created.
To better understand, let’s give an example.
In the system we have a user with username user.name.
We configure the IN email integration with: Model = DeepAdmin – User; Model Field = Username and Prefix: USR#, like in the example showed on the screenshot.
Now, an email is read from the mailbox. The subject of the email is New User: USR#user.name . DeepDesk understands that has to search the user entity and find a user with: username = user.name. This user exists, so DeepDesk will not create a new user but will update the existing user.
Then, an email with subject New User: USR#alva.edison . DeepDesk understands that has to search a user with: username = alva.edison. This user is not in the system, so DeepDesk will create a new user through an insert event.
Where can we define update or insert events?
In the tab System/Data we can see a filed called Insert and a field called Update.
This fields contain the code run after every email has been read by email integration.
To create a new user write in the field “Insert” this PHP code:
$mailSubject = $this->getMessage()->getSubject(); $mailBody = $this->getMessage()->getBodyText(); $row_data = explode('^', $mailBody); $userName = $row_data; $firstaname = $row_data; $lastname = $row_data; $this->getModel() ->setUsername($userName) ->setFirstname($firstaname) ->setLastname($lastname) ->save();
We are telling DeepDesk there is an email with a specific format that contains the data of a new user (we have to decide the format prior to implement the integration).
Now let’s schedule the job to read the mailbox.
In the tab Advanced set the value of the field Cron Expression
Now, we are telling DeepDesk to create a job, schduled every minute to read the mailbox.
Send a new email to the mailbox and let’s see what happens.
If everything is set the right way, a new user will be created in DeepDesk.