The line number refers to the line number inside the mail stored procedure - not your stored procedure....
It does sound like you have a NULL value in there somewhere.
Would suggest you should encapsulate all your set @stuff = (select ... ) in a isnull type test e.g. set @stuff = isnull( (select ...), '')
Or, if NULL values are meant to be impossible, then you might like to check those tables for NULL values.