SQL Off line / Database offline

SQL Off line / Database offline

How can I configure an alert to send an email if a SQL Server is off line or a database is off line. I need it for both.