question

dggvr avatar image
dggvr asked

TSQL database mail getting error

Hi, how to send the output as a HTML mail http://gallery.technet.microsoft.com/scriptcenter/All-Databases-Data-log-a36da95d#content This what I have done but getting error. Please help me to get the output as a HTML mail DECLARE @table NVARCHAR(MAX) ; SET @table = N'

DBSize

' + N'' + N'd.Dbnamed.dbstatusd.Recovery_ModelDBSIZE(file_size_mb + log_file_size_mb) as DBsize d.file_Size_MBd.Space_Used_MBd.Free_Space_MBl.Log_File_Size_MBlog_Space_Used_MB l.log_Free_Space_MBfs.Freespace' + CAST ( ( SELECT [d.Dbname] AS 'td','',[d.dbstatus] AS 'td','',[d.Recovery_Model] AS 'td','', (file_size_mb + log_file_size_mb) AS 'td','',[FILE_SIZE_MB] AS 'td','', [d.file_Size_MB] AS 'td','',[d.Space_Used_MB] AS 'td','',[d.Free_Space_MB] AS 'td','',[l.Log_File_Size_MB] AS 'td','', [log_Space_Used_MB] AS 'td','',[l.log_Free_Space_MB] AS 'td','',[fs.Freespace] AS 'td' from #dbsize d join #logsize l on d.Dbname=l.Dbname join #dbfreesize fs on d.Dbname=fs.name order by Dbname FOR XML PATH('tr'), TYPE ) AS NVARCHAR(MAX) ) + N'' ; EXEC msdb.dbo.sp_send_dbmail @profile_name='GmailAccount', --Change to your Profile Name @ recipients='Myname@gmail.com', --Put the email address of those who want to receive the e-mail @subject = 'DatabaseFileSizes', @body = @table, @body_format = 'HTML' ;
maildatabase-mail
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

KenJ avatar image KenJ commented ·
What is the error you are seeing?
0 Likes 0 ·

1 Answer

·
DenisT avatar image
DenisT answered
Use this file as an example [DatabasesSpaceUsage][1]. I created the script to email me the space used by each database on my Instances. It looks similar to what you're trying to do. Use my script as a template to customize it to your needs. Hope it helps! [1]: /storage/temp/1345-databasesspaceusage.txt

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.