1

I am creating a message inside a string using a Script task

The code would look like this:

Message = Description +"\n" + Message;

The idea is to receive a message like this:

Description
Description

and so on

Within a messagebox I can see this result, but when I open the mail, the message is composed of one single line:

Description1  Description2

I have also changed "\n" for "\n\r", Environment.NewLine. But it didn't work.

Could you explain me what am I doing wrong?

d2907
  • 798
  • 3
  • 15
  • 45
  • 2
    Send how? Which class did you use, what settings? Did you use HTML formatting? Newline characters are ignored in HTML and treated as whitespace – Panagiotis Kanavos Feb 15 '16 at 13:57
  • In ssis I am creating the message dynamically. At the end of the ETL I am adding the variable to the body of the mail using the Send Mail Task – d2907 Feb 15 '16 at 14:07
  • The SMTP standard uses CRLF, ie `\r\n`, for newline. WIndows also uses `\r\n`. AFAIK no OS uses `\n\r`. The duplicate question also explains that SMTP sends messages in lines, so your message is transmitted as a single line by all mail servers – Panagiotis Kanavos Feb 15 '16 at 14:15
  • Possible duplicate of [SMTP: \r\n\r (without second \n) as double newline](http://stackoverflow.com/questions/6167050/smtp-r-n-r-without-second-n-as-double-newline) – Panagiotis Kanavos Feb 15 '16 at 14:15
  • I believe the SSIS "Send Mail Task" attempts to send HTML-ified email so replace those `\n` with `
    ` and see what happens
    – billinkc Feb 16 '16 at 03:09

2 Answers2

4

You need to typecast it as below:

(DT_STR,2,1252)"\r\n"

For example...the below expression in Execute SQL task is dynamic SQL

"INSERT INTO [dbo].[OBJ_COUNT]([OBJ_NAME], [OBJ_COUNT]) VALUES ( " + "'EMPLOYEE_MASTER', " + (DT_STR, 10, 1252) (@[User::EMP_MAST_COUNT])+" );" + (DT_STR,2,1252)"\r\n" + "GO " + (DT_STR,2,1252)"\r\n" + "INSERT INTO [dbo].[OBJ_COUNT]([OBJ_NAME], [OBJ_COUNT]) VALUES ( " + "'DEPT_MASTER', " + (DT_STR, 10, 1252) (@[User::DEPT_MAST_COUNT])+" );" + (DT_STR,2,1252)"\r\n"+ "GO "

And will give output as below...

INSERT INTO [dbo].[OBJ_COUNT]([OBJ_NAME], [OBJ_COUNT]) VALUES ( 'EMPLOYEE_MASTER', 2514);
GO 

INSERT INTO [dbo].[OBJ_COUNT]([OBJ_NAME], [OBJ_COUNT]) VALUES ( 'DEPT_MASTER', 2541);
GO 
cfnerd
  • 3,658
  • 12
  • 32
  • 44
3

Try "\n\n" . This works but adds an extra line break. In most cases it is adequate.

jayt.dev
  • 975
  • 6
  • 14
  • 36