title: How to query Alert System Enable mail profile properties
body: <p>In order to send automated job failure notifications from SQL Server Agent, you must configure Database Mail and then to to <code>SQL Agent properties &gt; Alert System &gt; Mail Session &gt; Enable mail profile</code> to configure the <code>mail system</code> and <code>mail profile</code> to be used to send the email notifications.  We have many servers, and would like to setup a central cross-server job that ensures that the <code>Enable mail profile</code> option is checked across various servers, because otherwise, the scheduled jobs fail silently without sending an email notification.  </p>
  
  <p>Is there a <em>supported</em> way to query the <code>msdb</code> database to get to these settings using T-SQL (or by some other way programmatically)? </p>
  
  <p>Running a SQL Profiler trace while bringing up the properties page in the SQL Server Agent UI shows references to <code>msdb.dbo.sp_get_sqlagent_properties</code> which is an undocumented procedure (I would prefer to use documented objects to help future-proof our solution), and several calls to  <code>master.dbo.xp_instance_regread</code> which I would imagine the reg keys could change per each SQL Server instance installation. </p>
  
  <p>Does anyone know of a way to query to check whether the <code>enable mail profile</code> option is configured, and also retrieve the <code>mail profile</code> that is designated in the SQL Agent Alert System configs? Most of our servers are SQL Server 2008 R2, with some SQL 2012.  I would prefer SQL 2008+ support.</p>
  
  <p>Thanks in advance!</p>