我正在尝试使用SQL Server msdb并通过将正文格式化为HTML来发送电子邮件通知。
我想知道是否可以将附件文件作为Excel或.csv
文件发送。
这是我的代码:
Declare @HTMLbody nvarchar(max),
@NumChassis varchar(100),
@Marque varchar(100),
@Modele varchar(100),
@Finition varchar(100),
@SQL nvarchar(max)
set @SQL =''
Set @HTMLbody = '<!DOCTYPE html> <head><title>Aging stock notification</title></head><body>'
set @HTMLbody = @HTMLbody + '<center><h1> Notification des véhicules en stock</h1></center> '
set @HTMLbody = @HTMLbody + '<center><p> Vous pouvez visualisez la liste des chassis en stock depuis plus de 120 jours pièces jointes </p> </center>'
set @HTMLbody = @HTMLbody + ' <center> '
set @HTMLbody = @HTMLbody + @SQL + '</table> </center> <center><a href="http://Dashboard"><b>Voir plus de détails sur le tableau de bord</b> </a></center> '
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'Admin_smtp',
@body_format ='HTML',
@recipients = 'MAIL',
@body = @HTMLbody,
@query = 'select top(10) a.NUM_CHASSIS,a.MARQUE,a.MODELE,a.FINITION ,DATEDIFF(DAY, a.DATE_FIN_OF, GETDATE()) as Age from [DashboardPowerBi].[dbo].[BI_SVC_PROD_FIN_OF] as a
join [DashboardPowerBi].[dbo].[BI_SVC_INCADEA_STOCK_VN] as b
on a.NUM_CHASSIS = b.VIN
where b.CMD_Vente_Incadea = 0 and b.Fact_Av_Incadea =1 and DATEDIFF(DAY, a.DATE_FIN_OF, GETDATE()) > 120',
@subject = 'This is a test',
@attach_query_result_as_file=1 ;
有人可以帮我吗?