Send mail hook merge

all wanted features extracted from the send-mail-hook branch, ready to be merged