• Hi Jeff,

    Actually, after a day of on and off tinkering, the SP has changed a bit. I had to make a separate procedure on MSDB that the SP I posted calls to send the email. What I'm stuck on now is getting db sendmail to execute the query I want correctly. This could potentially be solved by creating an actual table that my results from the original query get selected into, but here:

    use msdb

    go

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    alter procedure aw_mail

    as

    declare @sql nvarchar (max)

    set @sql = 'exec sp_send_dbmail @profile_name = ''Erik'',

    @recipients = ''erik@email.com'',

    @subject=''Service file moved'',

    @body=''File moved to \\server\path\'',

    @query = ''exec cp_cmdshell dir \\server\path\ /B /A-D /O-D'''

    exec(@sql)

    Results in this error:

    Msg 22050, Level 16, State 1, Line 0

    Error formatting query, probably invalid parameters

    Msg 14661, Level 16, State 1, Procedure sp_send_dbmail, Line 495

    Query execution failed: Msg 15404, Level 16, State 19, Server P42, Line 1

    Could not obtain information about Windows NT group/user 'Erik', error code 0x6e.