Fixed some issues with sending emails.

Change-Id: I8267791d04f7d2e739b43cab704ad9c3d5a964c8