Did you look at the code in the link? It does almost what you require and can do exactly what you require with only minor changes.
Your code was aimed at messages going into the inbox. If you want it to work for sent items, you are going to have to setup a second event related to the sent items folder.