Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8718323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:31:00+00:00 2026-06-13T06:31:00+00:00

I’m trying to send an email from a scheduled SQL Agent job using sp_send_dbmail

  • 0

I’m trying to send an email from a scheduled SQL Agent job using sp_send_dbmail and receive the following 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 504
Query execution failed: Msg 15404, Level 16, State 19, Server MyServer, Line 1
Could not obtain information about Windows NT group/user ‘MyDomain\sqlagent’, error code 0x5.

Here is the code from the job step:

DECLARE @SQL NVARCHAR(400)
SELECT @SQL = 'SELECT COUNT(staff_id) FROM Staff'

EXEC msdb.dbo.sp_send_dbmail
@recipients = 'me@myemail.com',
@subject = 'Email Alert',
@body = 'Test',
@query = @SQL,
@execute_query_database = 'MyDB'

SQL Agent is running under a domain account [MyDomain\sqlagent]. I granted this user db_owner permission in the MyDB database in addition to adding it as a member of the DatabaseMailUserRole in msdb. Still no luck. If I remove the @query and @execute_query_database parameters it will send a ‘test’ email. However, I need to attach the results from the query.

Any help is appreciated, thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:31:02+00:00Added an answer on June 13, 2026 at 6:31 am

    I’ve run into some strange errors with AD in the past. I would recommend checking that the account you are running this under has it’s attributes readable within AD. The quickest way to do that would be to run

    exec xp_logininfo 'MyDomain\sqlagent'
    

    and seeing if you get the same error. If you do, check the security properties of the domain account [right click the user in Active Directory > Properties > Security tab] and set Read permissions for Authenticated Users.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to send email from java using SQL Server sp_send_dbmail From within
I'm trying to send email from Clojure using the following code: Helper function that
i am trying to send email using mail chimp api but the following error
I am trying to send email using gmail from my mvc application. I am
I am trying to send email using Exchange 2007 from a console app using
I am trying to send an email (using Outlook mail) from a jsp page.
I am trying to send an email via GMail from ASP.Net using the code
I am trying to send Email using java mail API from with in a
I am trying to use the below code to send email from asp.net(C#). using
I am trying to send email using the following method in my action class:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.