Bug fix for sending emails