November 14, 2006 at 4:16 am
Hi,
We have a default set of email messages in a SQL table with the appropriate one being retrieved depending on the conditions. The text is in the form of 'Dear <userName>, The NSS suggestion from <entrant> (NSS ID: <goshID> ) has been updated and requires your comments. Please could you open the attached website to load the NSS management system.' The <userName>, <entrant> and <goshID> get replaced with variables and the string included in the @message in xp_sendmail.
The problem is that the email is received with the text string as one long line with no carriage returns or line breaks. So although the data is there the formatting looks terrible.
How can a string be split with carriage returns or line breaks to format the @message for inclusion in the email so that it looks reasonable when received?
rgds
denis
November 14, 2006 at 5:32 am
You can enter line breaks into the data in your column like this:
declare @message varchar(1000)
set @message = 'This is the first line'+char(13)+'This is the second line'
select @message
This is the first line
This is the second line
(1 row(s) affected)
Line breaks will be "invisible" when viewing data in the table, but should work correctly when the message is generated.
Switch to "Results in Text" in QA when testing this.
EDIT: If you are using HTML formatting, you could also enter <br> tags into the text (untested , just an idea).
November 14, 2006 at 5:44 am
As a side note, that should be char(13) + char(10) [CR LF] according to the email standard.
Also when testing you can use:
print @message
This will display the line breaks as well (output will appear in the messages window).
November 14, 2006 at 8:07 am
Thanks very much, it works perfectly.
rgds
denis
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply