[英]SQL Server sp_send_dbmail prevent html encoding in body
How can I prevent encoding within the body of an email sent using SQL Server's sp_send_dbmail
?如何防止在使用 SQL Server 的
sp_send_dbmail
发送的电子邮件正文中进行编码?
Example:例子:
EXEC msdb.dbo.sp_send_dbmail
@recipients='my.email@somedomain.com',
@subject = 'SQL email test',
@body = 'this+that',
@body_format = 'HTML'
The html source of the email that I receive looks like this:我收到的电子邮件的 html 来源如下所示:
this`+`that
and the body looks fine:身体看起来很好:
this+that
However, what if I want the SOURCE to still have the + instead of the +
但是,如果我希望 SOURCE 仍然有 + 而不是
+
? ?
Long back story on why I need to do this, but solving this would help me immensely.关于为什么我需要这样做的长篇大论,但解决这个问题将极大地帮助我。 Is there a way to "escape" the + in my body parameter?
有没有办法“转义”我的身体参数中的 + ? Or any other idea on how to prevent this encoding?
或者关于如何防止这种编码的任何其他想法?
You can try doing a simple XML hack:您可以尝试做一个简单的 XML hack:
DECLARE @source VARCHAR(255) = 'this`+`that';
DECLARE @body VARCHAR(255)= CAST ( CAST ( 'this`+`that' AS XML ) AS VARCHAR(255) );
SELECT @body AS body;
Returns退货
+-------------+
| body |
+-------------+
| this`+`that |
+-------------+
This will not however remove your backticks.但是,这不会删除您的反引号。 You can add a call to
REPLACE
if needed:如果需要,您可以添加对
REPLACE
的调用:
DECLARE @body VARCHAR(255)= REPLACE ( CAST ( CAST ( 'this`+`that' AS XML ) AS VARCHAR(255) ), '`', '' );
Which results in:结果是:
+-----------+
| body |
+-----------+
| this+that |
+-----------+
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.