Fix smtp email sending bug.

Fixed some bugs in when SMTP email sending is enabled.