moved mail into loop