SQL Server 2008: How to send an email when a step in a SQL Server agent job fails, but overall job succeeds

You could create a Stored Proc for steps 1-4, with error handling that notifies you via email on failure.

Something like:

CREATE PROCEDURE TestEmailOnFail
AS
BEGIN
    BEGIN TRY
        /*
            Perform some action that might fail
        */
        SELECT 0/0; --THIS WILL FAIL
    END TRY
    BEGIN CATCH
        DECLARE @subject nvarchar(max) = 'Job Failure Notification';
        DECLARE @body nvarchar(max) = 'TestEmailOnFail Job Failed' 
            + CHAR(10) + CHAR(13) + 'Error Number:  ' + CAST(ERROR_NUMBER() AS nvarchar(max))
            + CHAR(10) + CHAR(13) + 'Error Message: ' + ERROR_MESSAGE();
        DECLARE @to nvarchar(max) = '[email protected]';
        DECLARE @profile_name sysname = 'SQLMailProfileName';
        EXEC msdb.dbo.sp_send_dbmail @profile_name = @profile_name,
            @recipients = @to, @subject = @subject, @body = @body;
    END CATCH
END

I just tested this using my SQL Mail Profile, and my email address and got the following email:

TestEmailOnFail Job Failed
Error Number:  8134
Error Message: Divide by zero error encountered.

  1. Create a step 4a, which sends a general e-mail (like that @Max pointed out) that "one of the first 4 steps failed." You can do this using database mail or whatever you're using now to alert on job failure.
  2. Step 4a is set to move to Step 5 on success.
  3. Step 4 is set to move to Step 5 on success.
  4. Steps 1-4 are set to move to step 4a on failure.

If you need to know which step failed, you may just want to put the logic into each step (similar to what Max proposed) to do a TRY/CATCH inside the job step logic rather than build 4 handler steps and use the job scaffolding.