refactored email sending to have prettier and more loggy code