mail logic