Search code examples
sql-servert-sqldatabase-mail

Database mail is not working in SQL Server


I have created a proc to send mail with attachment (attachment is from query result)

while running manually it working fine

Scheduled proc using Job. Where in job it is not sending any mail. Also job is not failing

Checked in sysmail_allitems but there is no entry for job mails but for manual run I can find entry.

I suspect some permission issue on service account which runs job.


Solution

  • Sending emails through the database requires some special privileges, it's likely that the account the Job executes under doesn't have them.

    Check which SQL account is executing the job, then execute:

    EXECUTE AS LOGIN = 'TheSQLLoginHere'; 
    EXEC mySendMailSP;
    

    You will see the missing privileges there. You can either supply them or change the account for that Job.