Showing posts with label Query to get default mail profile?. Show all posts
Showing posts with label Query to get default mail profile?. Show all posts

Query to check Default Database Mail profile in SQL Server?

Query to check default Database Mail profile in SQL Server?

SELECT TOP 1 name
FROM msdb.dbo.sysmail_profile p
JOIN msdb.dbo.sysmail_principalprofile pp ON pp.profile_id = p.profile_id AND pp.is_default = 1

Suppose if you want to take the value in a variable then you can use the below query:

DECLARE @defaultProfileName NVARCHAR(100)=''
SELECT TOP 1 @defaultProfileName=name
FROM msdb.dbo.sysmail_profile p
JOIN msdb.dbo.sysmail_principalprofile pp ON pp.profile_id = p.profile_id AND pp.is_default = 1