I noticed that HTTP request will be processed according to the ngx_http_phases and mail core module doesn't have the same mechanism. So it seems I have to refer to his code if I don't want to modify the core code... Posted at Nginx Forum: http://forum.nginx.org/read.php?2,216892,216989#msg-216989