send_templated_mail utility function