SQL Server SP_SEND_DBMAIL 图像文件附件
我正在表上使用触发器来使用 sp_send_dbmail 发送电子邮件。
我想在图像类型的电子邮件中包含文件附件。
jpeg 的原始数据存储在二进制类型的 ndl_Image 列中。
我有以下代码:-
DECLARE @ReferenceID varchar(max)
DECLARE @Recipient varchar(Max)
DECLARE @Body varchar(max)
DECLARE @Subject varchar(max)
DECLARE @Q varchar(max)
--Get the EntryId and FormID for the inserted data.
SET @ReferenceID = 40
SET @Recipient = (SELECT ndl_CategorySendTo FROM ndl_config WHERE ndl_CategoryName = 'Dead Animal')
SET @Body = '<html>A new request has been created.</html>'
SET @Subject = 'NDL Report It: New Request #'+@ReferenceID
SET @Q = 'SELECT ndl_Image from dbo.ndl_data where ndl_ID ='+@ReferenceID
--Execute the stored procedure to send mail.
EXEC msdb.dbo.sp_send_dbmail
--Pass it the following paramaters.
@recipients=@Recipient,
@body=@Body,
@subject=@Subject,
@profile_name='NDLProfile',
@body_format ='HTML',
@execute_query_database='NDL_MX',
@query = @Q,
@attach_query_result_as_file = 1,
@query_attachment_filename = 'image.jpg'
这工作正常,但如果我注释掉最后一行,似乎会将查询作为文本文件返回。
如何获取 jpeg 文件形式的附件???
谢谢。
I am using a trigger on a table to send an email using sp_send_dbmail.
I want to include a file attachment in the email of an image type.
The raw data for the jpeg is stored in the ndl_Image column which is of type binary.
I have the following code:-
DECLARE @ReferenceID varchar(max)
DECLARE @Recipient varchar(Max)
DECLARE @Body varchar(max)
DECLARE @Subject varchar(max)
DECLARE @Q varchar(max)
--Get the EntryId and FormID for the inserted data.
SET @ReferenceID = 40
SET @Recipient = (SELECT ndl_CategorySendTo FROM ndl_config WHERE ndl_CategoryName = 'Dead Animal')
SET @Body = '<html>A new request has been created.</html>'
SET @Subject = 'NDL Report It: New Request #'+@ReferenceID
SET @Q = 'SELECT ndl_Image from dbo.ndl_data where ndl_ID ='+@ReferenceID
--Execute the stored procedure to send mail.
EXEC msdb.dbo.sp_send_dbmail
--Pass it the following paramaters.
@recipients=@Recipient,
@body=@Body,
@subject=@Subject,
@profile_name='NDLProfile',
@body_format ='HTML',
@execute_query_database='NDL_MX',
@query = @Q,
@attach_query_result_as_file = 1,
@query_attachment_filename = 'image.jpg'
This works ok but seems to return the query as a text file if i comment out the last line.
How can I get the attachment as a jpeg file????
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这是不可能的。正如 SP_SEND_DBMAIL 文档中所述:
I don't think this is possible. As specified in the documentation for SP_SEND_DBMAIL:
下面的示例将图像嵌入到 <图像>标签,适用于 jpeg、png 等。它不能解析 PDF,但至少可以处理图像。
The sample below will imbed images into the < img > tag, which will work for jpeg, png, and such. It won't solve PDFs, but it does work with images, at least.