How to add a new line in email?
Hi, folks!
I'm sending emails with %Net.MailMessage.
How can I add a new line for the email body?
The code is:
dim msg as %Net.MailMessage = ##class(%Net.MailMessage).%New()
set msg.Charset="UTF-8"
do msg.TextData.Write("Dear "_Username)
do msg.TextData.Write("Line1")
do msg.TextData.Write("Line2")
And I'm getting in email:Dear UserLine1Line2
How can I get:
Dear User Line1 Line2
Comments
what about a
do msg.TextData.WriteLine("Line with CRLF")
Thanks!
WriteLine didn't help actually. I'm on Ubuntu, 2017.1. Still getting all in one line. Will try with $C(10).
Yes, the issue was in HTML.
I'm having:
set msg.ContentType = "text/html" set msg.IsHTML=1
So, <br/> works in this case to make lines like:
do msg.Write("<br/>")
I normally use $CHAR(10), this function represent the ascii character you need
From Class documentation, you can see
so, you have two methods Write and WriteLine
But anyway even with Write method you can use $c(13) to put line end
my quick test says there are two chars, CR and LF, on an AIX and on Ubuntu
USER>s str=##class(%GlobalCharacterStream).%New()
USER>d str.WriteLine("Test")
USER>d str.Rewind()
USER>zzdump str.Read(100)
0000: 54 65 73 74 0D 0A Test..
USER>
USER>w $zv
Cache for UNIX (IBM AIX for System Power System-64) 2017.1 (Build 792U) Mon Mar 20 2017 19:19:37 EDT
USER>-----------------
USER>s str=##class(%GlobalCharacterStream).%New()
USER>d str.WriteLine("Test")
USER>d str.Rewind()
USER>zzdump str.Read(100)
0000: 54 65 73 74 0D 0A Test..
USER>
USER>w $zv
Cache for UNIX (Ubuntu Server LTS for x86-64) 2017.1 (Build 792U) Mon Mar 20 2017 19:22:31 EDT
USER>Maybe, your problem has nothing to do with Cache?
Regards,
Julius
Maybe you're sending HTML emails?
WriteLine works only for plaintext emails.
Use <br/> for new line in HTML emails.
To send HTML emails specify these settings:
set mail.ContentType = "text/html" set mail.IsHTML = 1 set mail.Charset = "utf-8"