Before Executing a job and sending mail to an User we need to configure our mail services in SQL Server:
Follow the steps below to configure a mail services in SSMS2014.
Step : 1
Open SSMS
Step : 2
Go to Management -> Database Mail->Configure Database Mail
Step : 3
Step : 4
Step : 5
Choose any Profile Name
Step : 6
Step 7 :
Click OK->OK
Step : 8
Go to SQL Server Agent->Operators->Right Click->New Operator
Operator Created with your given Name.
Now we can go for testing steps,Lets have a look
Step : 9
Go to Management->Database Mail->Right Click->
Step : 10
Select Profile Name
Follow the steps below to configure a mail services in SSMS2014.
Step : 1
Open SSMS
Step : 2
Go to Management -> Database Mail->Configure Database Mail
Step : 3
Step : 4
Step : 5
Choose any Profile Name
Step 7 :
Click OK->OK
Step : 8
Go to SQL Server Agent->Operators->Right Click->New Operator
Operator Created with your given Name.
Now we can go for testing steps,Lets have a look
Step : 9
Go to Management->Database Mail->Right Click->
Step : 10
Select Profile Name
Step :11
Create a new job with following steps
Go to SQL Server Agent->Jobs->New Job->General
Keep some name->Go To Steps tab ->Steps Name->Select Database->Command
Put below query to Command box
Execute the Job and see the mail. I hope you will get.EXEC msdb.dbo.sp_send_dbmail@profile_name = 'Operator Name',@recipients = 'mail ID',@query = 'SELECT COUNT(*) as No_Counts FROM DB.Schema_Name.Table_Name',@subject = 'No of Employees Working';