我有一个 proc,我在其中生成带有链接的小型 html 文档,并通过 xp_smtp_sendmail proc 将其发送出去。链接是根据查询结果生成的,链接很长。这在大多数情况下都有效。但是,有时链接会由于在查询字符串变量名称中插入空格而中断,即 &Name=John。
这可能因电子邮件客户端而异(相同的链接在 Gmail 中有效,但由于空格可能无法在 comcast 中有效。空间似乎是随机插入的,因此在每个损坏的电子邮件链接空间中可能会破坏其他查询字符串变量。当我从 proc 执行 PRINT链接很干净,没有空格。
这是我在主过程中执行的邮件过程的示例(它获取查询结果并为@Message 生成 html)。无论我是否对 url 进行编码,似乎都会插入空格。
预先感谢您的帮助。如果此处显示不正确,我可以发送更简洁的代码版本。
....上面的查询结果
SET @Message = NULL
SET @Message = @Message +
+ '<br/>Dear ' + @FirstName + ' ' + @LastName + ','
+ '<br/><br/>Recently you took "' + @Title + '". '
+ 'In response to the question "What is it?" '
+ 'you responded "' + @Response + '".'
+ '<br/><br/>Following up on previous mailing'
+ '<br/><br/>Please click on the link below'
+ '<br/><br/><a href="' + @Link + '">Please click here</a>'
+ '<br/><br/>plain text'
+ '<br/><br/>plain text,'
+ '<br/><br/>plain text<br/>
plain text<br/>
plain text<br/>
plain text<br/>
plain text<br/>
plain text
EXEC @rc = master.dbo.xp_smtp_sendmail
@FROM = 'any@any.com',
@FROM_NAME = 'Any User',
@TO = @Email,
@priority = N'NORMAL',
@subject = N'My email',
@message = @Message,
@messagefile = N'',
@type = N'text/html',
@attachment = N'',
@attachments = N'',
@codepage = 0,
@server = 'smtp.server.any'