Здравствуйте, у меня есть PowerShell, который генерирует таблицу HTML и использует Send-MailMessage для отправки его через Outlook. Похоже, только поддерживает 25 строк. Можно найти, если проблема в моем коде или проблема конфигурации Outlook.
HTML в порядке, поэтому похоже, что проблема в Outlook
EMAIL
HTML ТАБЛИЦА ЗАПУСКА НА БРАУЗЕРЕ:
Код оболочки питания:
[CmdletBinding()]
param(
[Parameter(Mandatory=$True, position=0)]
[string] $DatabaseServer,
[Parameter(Mandatory=$True, position=1)]
[string] $DatabaseName,
[Parameter(Mandatory=$True, position=2)]
[string] $TargetEmail
)
$query = "DECLARE @html nvarchar(MAX);
EXEC spQueryToHtmlTable @html = @html OUTPUT,
@query = 'SELECT
RUNID, LAUNCHEDBY, RUNSTART, PROCESSTYPE, PROCESSNAME
FROM mytable
WHERE datediff(minute,RUNSTART,GETDATE()) > 15 AND RUNEND IS NULL', @orderBy = 'ORDER BY RUNSTART';
SELECT @html as html
"
$ConString = "Server=$DatabaseServer;Database=$DatabaseName;Integrated Security=SSPI;Connect Timeout=30"
$result = Invoke-Sqlcmd -Query $query -ConnectionString $ConString
$body = "The following processes have been locked for more than 15 minutes: `n" + $result.html
Send-MailMessage -To $TargetEmail -From “test@test.com” -Subject “[$DatabaseName] Alert - Processes running for >= 15 mins“ -Body $body -BodyAsHtml -SmtpServer “smtp.smtp.com”
SQL Код:
GO
/****** Object: StoredProcedure [dbo].[spQueryToHtmlTable] Script Date: 15/04/2020 14:45:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROC [dbo].[spQueryToHtmlTable]
(
@query nvarchar(MAX), --A query to turn into HTML format. It should not include an ORDER BY clause.
@orderBy nvarchar(MAX) = NULL, --An optional ORDER BY clause. It should contain the words 'ORDER BY'.
@html nvarchar(MAX) = NULL OUTPUT --The HTML output of the procedure.
)
AS
BEGIN
SET NOCOUNT ON;
IF @orderBy IS NULL BEGIN
SET @orderBy = ''
END
SET @orderBy = REPLACE(@orderBy, '''', '''''');
DECLARE @realQuery nvarchar(MAX) = '
DECLARE @headerRow nvarchar(MAX);
DECLARE @cols nvarchar(MAX);
SELECT * INTO #dynSql FROM (' + @query + ') sub;
SELECT @cols = COALESCE(@cols + '', '''''''', '', '''') + ''['' + name + ''] AS ''''td''''''
FROM tempdb.sys.columns
WHERE object_id = object_id(''tempdb..#dynSql'')
ORDER BY column_id;
SET @cols = ''SET @html = CAST(( SELECT '' + @cols + '' FROM #dynSql ' + @orderBy + ' FOR XML PATH(''''tr''''), ELEMENTS XSINIL) AS nvarchar(max))''
EXEC sys.sp_executesql @cols, N''@html nvarchar(MAX) OUTPUT'', @html=@html OUTPUT
SELECT @headerRow = COALESCE(@headerRow + '''', '''') + ''<th>'' + name + ''</th>''
FROM tempdb.sys.columns
WHERE object_id = object_id(''tempdb..#dynSql'')
ORDER BY column_id;
SET @headerRow = ''<tr>'' + @headerRow + ''</tr>'';
SET @html = ''<table border="1">'' + @headerRow + @html + ''</table>'';
';
EXEC sys.sp_executesql @realQuery, N'@html nvarchar(MAX) OUTPUT', @html=@html OUTPUT
END
Можете ли вы помочь мне найти эту проблему? Спасибо!