As derscribe in webBlog Receiving E-Mail and processing it with ABAP – Version 610 and Higher and similar, you can put the code for manage email directly in class that process the mail. Unfortunatly is difficult to monitor process and keep in trace. You can use the class cl_trace_bcs, but if you want to debug it you need to define a infine loop and get it from SM50.
So I develop a simple solution that give you the (probabily) final solution.
We define a single class that take and process the inbound mail and save it on db. After that a standard programm will take the mail from db and process them for any activity you need (for example to create activity, to attach file, to process a “system command”)
Here the code for the class that take into db the mail:
And the code for the report that fisicaly process the mail.
You can enanche this by adding a raise event for immediate processing and a lock mecchanism to prevent duplicate read and process from db.