如何在 html 中嵌入图像并通过 msdb.dbo.sp_send_dbmail 将 html 作为电子邮件发送?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/663048/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to embed image in html and send html as email by msdb.dbo.sp_send_dbmail?
提问by David.Chu.ca
I can use msdb.dbo.sp_send_dbmail to send out email in html format. It is very nice for text only in terms of format. For example:
我可以使用 msdb.dbo.sp_send_dbmail 以 html 格式发送电子邮件。仅在格式方面对文本来说非常好。例如:
EXEC msdb.dbo.sp_send_dbmail
@recipients = @p_recipients,
@subject = @v_subject,
@body=@emailHTML,
@body_format = 'HTML';
However, if I want to include images such as trend generated from data on my SQL server, and to embed them in the html (@emailHTML), what html tag should I use?
但是,如果我想包含从我的 SQL 服务器上的数据生成的趋势等图像,并将它们嵌入到 html (@emailHTML) 中,我应该使用什么 html 标记?
If I use [img] tag, then I need to set the src attribute. The image generated are saved in my local SQL server's hard disk. I could place them in IS server web page area. But all those web servers are intranet accessible but not outside of my work.
如果我使用 [img] 标签,那么我需要设置 src 属性。生成的图像保存在我本地 SQL 服务器的硬盘中。我可以将它们放在 IS 服务器网页区域。但是所有这些网络服务器都可以在内部网访问,但不能在我的工作之外。
Is there any way to embed image in the email? How I can set html to embed images?
有没有办法在电子邮件中嵌入图像?如何设置 html 以嵌入图像?
I am using Microsoft SQL server 2005. I prefer to msdb.dbo.sp_send_dbmail to send out reports out as email. I have much control of html format. If there is no way to that, I may have to send images as attachment files.
我使用的是 Microsoft SQL Server 2005。我更喜欢使用 msdb.dbo.sp_send_dbmail 将报告作为电子邮件发送出去。我对 html 格式有很多控制。如果没有办法,我可能不得不将图像作为附件发送。
回答by David.Chu.ca
I think I got the answer:
我想我得到了答案:
EXEC msdb.dbo.sp_send_dbmail
@recipients = '[email protected]',
@subject = 'test',
@file_attachments = 'C:\MyFolder\Test\Google.gif;C:\MyFolder\Test\Yahoo.gif',
@body=N'<p>Image Test</p><img src="Google.gif" /><p>See image there?</p>
<img src="Yaoo.gif" /><p>Yahoo!</p>',
@body_format = 'HTML';
basically, add the image as attachment, and the src attribute contains just the image file name, no any path is needed. If more than one image files are needed, just use ";" to separate them.
基本上,将图像添加为附件,src 属性只包含图像文件名,不需要任何路径。如果需要多个图像文件,只需使用“;” 将它们分开。
I send email to my outlook email and it works. Try it to my yahoo email....
我将电子邮件发送到我的 Outlook 电子邮件,它可以正常工作。试试我的雅虎电子邮件....