I have several new servers that need Database Mail configured on them. I found the TechNet article describing how to add the profile and account via procedure calls, but is there a way to enable database mail and select the profile for the SQL Agent in the same manner?
SQL Server Agent Database Mail – How to Enable Using T-SQL
database-mailsql serversql-server-agentt-sql
Best Answer
The following T-SQL will enable Database Mail in SQL Server Agent:
For future reference, you can easily determine this by expanding the "SQL Server Agent" node in SQL Server Management Studio's Object Explorer pane. Then right-click on "SQL Server Agent", click "Properties", select "Alert System", enter the appropriate details, and click on "Script":