SQL Result sent via email

Hi Experts,

I always check my LOGs via this command:

dbcc sqlperf(logspace)

The result should be sent via email.
Can you guide me how ?
Eprs_AdminSystem ArchitectAsked:
Who is Participating?
 
Deepak ChauhanSQL Server DBACommented:
Please check the Database mail , sysmail account and sysmail profile is enabled on your system where you are running this SP if this is not configured you can not send the email.

You can check using below query.

select * from dbo.sysmail_account
select  * from dbo.sysmail_profile

if mail is configured on this system.
replace the parameter in below code and execute.

EXEC msdb.dbo.sp_send_dbmail
@profile_name = '<profilename>',
@recipients = '< receipent email address>',
@subject='<sublect line like Log Space or whatever>',
@query = '< tsql query here>',
@attach_query_result_as_file = 1
0
 
David ToddSenior DBACommented:
Hi,

Use sp_send_dbmail
https://msdn.microsoft.com/en-us/library/ms190307.aspx

Note that there are parameters for the query to run etc ...

Regards
  David
0
 
Eprs_AdminSystem ArchitectAuthor Commented:
Hi,

I am not sure if this sp is already installed on my sql.
With which command I can check all stored procedures ?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Eprs_AdminSystem ArchitectAuthor Commented:
When I copy this command, it is not working...

sp_send_dbmail [ [ @profile_name = ] 'profile_name' ]
    [ , [ @recipients = ] 'recipients [ ; ...n ]' ]
    [ , [ @copy_recipients = ] 'copy_recipient [ ; ...n ]' ]
    [ , [ @blind_copy_recipients = ] 'blind_copy_recipient [ ; ...n ]' ]
    [ , [ @from_address = ] 'from_address' ]
    [ , [ @reply_to = ] 'reply_to' ] 
    [ , [ @subject = ] 'subject' ] 
    [ , [ @body = ] 'body' ] 
    [ , [ @body_format = ] 'body_format' ]
    [ , [ @importance = ] 'importance' ]
    [ , [ @sensitivity = ] 'sensitivity' ]
    [ , [ @file_attachments = ] 'attachment [ ; ...n ]' ]
    [ , [ @query = ] 'query' ]
    [ , [ @execute_query_database = ] 'execute_query_database' ]
    [ , [ @attach_query_result_as_file = ] attach_query_result_as_file ]
    [ , [ @query_attachment_filename = ] query_attachment_filename ]
    [ , [ @query_result_header = ] query_result_header ]
    [ , [ @query_result_width = ] query_result_width ]
    [ , [ @query_result_separator = ] 'query_result_separator' ]
    [ , [ @exclude_query_output = ] exclude_query_output ]
    [ , [ @append_query_error = ] append_query_error ]
    [ , [ @query_no_truncate = ] query_no_truncate ] 
…………[ , [@query_result_no_padding = ] @query_result_no_padding ] 
    [ , [ @mailitem_id = ] mailitem_id ] [ OUTPUT ]

Open in new window

0
 
David ToddSenior DBACommented:
Hi,

The code you posted is the syntax - square brackets indicating optional elements, ellipsis indicating repeated elements etc.

You will need to edit this all to suit - see the examples further down the page ...

Regards
   David
0
 
Eprs_AdminSystem ArchitectAuthor Commented:
Hello,
how to find out, if the profile is created ?

@profile_name = '<profilename>',
0
 
Deepak ChauhanSQL Server DBACommented:
Hi,

Run this query in the ssms query window. it will show you profile name in the name column.

select * from msdb.dbo.sysmail_profile
0
 
Eprs_AdminSystem ArchitectAuthor Commented:
ok now it works -> thanks my friend
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.