To send mail through the SQL Server, you must first configure Database Mail. You can find details in the article “How To Configure Database Mail On SQL Server“.
Let’s create a job after the Database Mail Configuration is completed. In my article “How To Create a SQL Server Job” you can see how the job was created.
From the SQL Server Agent section, click View Job Activity and right click on the XYZ job I created in the article I mentioned above and click on Properties. I’m accessing step’s content by clicking edit in the “Steps” section. I’m writing the wrong TSQL code as follows for Job to fail.
Then we mark the E-mail in Notifications and we select the Operator we defined in the Database Mail Configuration from the check box next to it.
“When the Job fails” remains selected. In this way, it will send an e-mail to the people defined in Operator if the job fails.
I’m running the job to do the test and when the job gets the error, it sends me a mail as follows.