gpt4 book ai didi

html - sp_send_dbmail 在正文中嵌入 mhtml 文件

转载 作者:技术小花猫 更新时间:2023-10-29 12:40:53 27 4
gpt4 key购买 nike

我有一个 SSRS 报告,我需要使用 SQL Server 中的 sp_dbmail 存储过程将其嵌入到电子邮件正文中。我可以使用 Outlook 的前端执行此操作,方法是在附加文件时使用“插入为文本”选项附加 SSRS 报告的 .mhtml 导出。

有没有办法使用 sp_dbmail 存储过程来做到这一点?

我正在使用 SQL Server 2014 标准版

最佳答案

是的,可以通过将文件内容读入变量,然后将其传递给 sp_send_dbmail。方法如下:

declare @htmlBody varchar(max)

SELECT @htmlBody=BulkColumn
FROM OPENROWSET(BULK N'c:\test\test.html',SINGLE_BLOB) x;



EXEC msdb.dbo.sp_send_dbmail
@profile_name = N'Email', -- you should use the profile name of yours, whatever is set up in your system.
@recipients = 'recipient_email_id',
@subject = 'Test',
@body = @htmlBody,
@body_format = 'html',
@from_address = 'sender_email_id';

这会将 c:\test\test.html 的内容嵌入到电子邮件正文中。当然,你可以在body中添加更多。

更新:

这仅在您正在阅读的文件包含 HTML 内容时有效。如果你想让它适用于mhtml,你需要将mhtml文件转换为html(详见@Pops贴出的答案关于如何将 mhtml 转换为 html)。

关于html - sp_send_dbmail 在正文中嵌入 mhtml 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42867662/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com