sp_send_dbmail

  • Hi experts, I use dbmail frequently but this time I want to send mail to whomever is designated as one of my SQL Server Agent operators specifically the operator named 'SQL Server Agent Operator'. What do I specify as the @Recipients=?

    Thank you.

  • You can use sp_notify_operator:

    sp_notify_operator

    [ @profile_name = ] 'profilename' ,

    [ @id = ] id ,

    [ @name = ] 'name' ,

    [ @subject = ] 'subject' ,

    [ @body = ] 'message' ,

    [ @file_attachments = ] 'attachment'

    [ @mail_database = ] 'mail_host_database'

    Or, you can set a variable and get the value from msdb.dbo.sysoperators:

    Declare @emailAddress nvarchar(100);

    Set @emailAddress = (Select s.email_address

    From msdb.dbo.sysoperators s

    Where name = 'MyName');

    Jeffrey Williams
    Problems are opportunities brilliantly disguised as insurmountable obstacles.

    How to post questions to get better answers faster
    Managing Transaction Logs

  • Thank you Jeffery. I will keep both methods on hand. For simplicity I think I try the second method first. Warm regards, Hope

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply