Insert database queries in to email template

See this thread: