Back to results for “SQL Server Agent & Job Scheduling”
SQL Server › SQL Server Agent & Job Scheduling

How do you configure a SQL Server Agent job to send an email alert if it fails?

Intermediate

Answer

You configure Database Mail with a valid mail profile, create an operator representing the person or team who should be notified, and then set up a notification on the job itself specifying that an email should be sent to that operator whenever the job fails, giving your team immediate visibility into problems without needing to manually check job history.
EXEC msdb.dbo.sp_add_operator @name = 'DBA Team', @email_address = 'dba@example.com';
EXEC msdb.dbo.sp_update_job @job_name = 'NightlyBackup', @notify_level_email = 2, @notify_email_operator_name = 'DBA Team';
Real-world example A team receives an immediate email alert whenever their nightly backup job fails, allowing them to quickly investigate and resolve the issue before it puts several days of data at risk.

Common follow-ups: What does the notify_level_email value of 2 actually mean?;What other notification methods besides email are available for job alerts?