Use toString() instead of casting

Coauthor: sfmailand