Database email job succeed but no email with attachment received

124 Views Asked by At

I have set a databasemail profile on SQL2014, created a job, run it and the job succeed but I don't receive any email with my attachment.

Here is my query:

declare @clientname as varchar(50)
set @clientname = 'ABCD'
declare @stagequery as varchar(max)
set @stagequery= 'select users.name, Organizations.Name from users
inner join Organizations on users.OrganizationId = organizations.OrganizationId
where Organizations.name = ' + @clientname

exec msdb.dbo.sp_send_dbmail
@recipients = '[email protected]'
,@body = 'test'
,@body_format = 'HTML'
,@subject = 'test result'
,@query = @stagequery
,@attach_query_result_as_file = 1
,@query_result_header = 1
,@query_attachment_filename   = 'Results.csv'
,@query_result_separator      = ';'
,@query_result_no_padding     = 1
,@exclude_query_output        = 1
,@append_query_error          = 0
,@query_no_truncate = 0
,@execute_query_database = 'mydatabase'

I have tried to run the job manually - succeeded but no email;

0

There are 0 best solutions below