Insert carriage return in smtp email body

tchaniel
Member Posts: 6
Hello everyone! I have searched the forums and I know this topic has been discussed a few times. The problem is that I have tried every suggestion I have come across and nothing is working. ](*,) I have defined two variables, CR and LF, as type char. I give them the ASCII values 13 and 10, respectively. When my code is run and the email is generated, there are no carriage returns in the emails. Here is the code I am using:
Mail.Body := FORMAT(cust."No.") + FORMAT(CR,0,'<CHAR>') + FORMAT(LF,0,'<CHAR>') +
FORMAT(cust.Name) + FORMAT(CR,0,'<CHAR>') + FORMAT(LF,0,'<CHAR>') +
FORMAT(cust."Phone No.") + FORMAT(CR,0,'<CHAR>')+FORMAT(LF,0,'<CHAR>') +
('Your order request has been accepted.');
I am using SMTP mail. Any help would be greatly appreciated!
Regards,
Tanya
Mail.Body := FORMAT(cust."No.") + FORMAT(CR,0,'<CHAR>') + FORMAT(LF,0,'<CHAR>') +
FORMAT(cust.Name) + FORMAT(CR,0,'<CHAR>') + FORMAT(LF,0,'<CHAR>') +
FORMAT(cust."Phone No.") + FORMAT(CR,0,'<CHAR>')+FORMAT(LF,0,'<CHAR>') +
('Your order request has been accepted.');
I am using SMTP mail. Any help would be greatly appreciated!
Regards,
Tanya
0
Comments
-
Don;t use format, just add them in to the string
test := 'This is line 1' + CRLF + 'This is line 2';David Singleton0 -
or in your case like this:tchaniel wrote:Mail.Body := cust."No." + CRLF + cust.Name CRLFcust."Phone No." + CRLF + 'Your order request has been accepted.';David Singleton0
-
You'll get an error if you try to add a chracter to a string, or at least you did when I started with NAV. I always had to do String + FORMAT(char).0
-
Thanks for your quick response, David! I have tried this as well. I get this error:
Type conversion is not possible because 1 of the operators contain an invalid type.
Code + Char
My modified code:
Mail.Body := cust."No." + CR + LF +
cust.Name + CR + LF +
cust."Phone No." + CR + LF +
('Your order request has been accepted.');
If I use FORMAT(cust."No.") + CR + LF + , I receive the following error:
Type conversion is not possible because 1 of the operators contain an invalid type.
Text + Char0 -
Also, I am using the SMTP Mail Codeunit(400).0
-
matttrax wrote:You'll get an error if you try to add a chracter to a string, or at least you did when I started with NAV. I always had to do String + FORMAT(char).
Well the CRLF needs to be a string not a char.
Here is some code from a working solution:
Name DataType Subtype Length
CRLF Text 2
CRLF := ' ';
CRLF[1] := 13;
CRLF[2] := 10;
Then you can just add CRLF to the text string.
How else would you do it?David Singleton0 -
tchaniel wrote:... I have defined two variables, CR and LF, as type char. I give them the ASCII values 13 and 10, respectively. ...
Regards,
Tanya
Sorry I missread that. So make it one text variable of len 2.David Singleton0 -
My new declarations and code:
Name DataType Subtype Length
CRLF Text 2
CRLF := '';
CRLF[1] := 13;
CRLF[2] := 10;
Mail.Body := FORMAT(cust."No.") + CRLF +
FORMAT(cust.Name) + CRLF +
FORMAT(cust."Phone No.") + CRLF + CRLF +
('Your order request has been accepted.');
Still no luck.0 -
Not that it matters too much but why do you keep putting the "format" back in there? What does it do?
Anyway the code above I copied from a client that has been using it for many years without a problem, so not sure what the issue is.David Singleton0 -
David Singleton wrote:Not that it matters too much but why do you keep putting the "format" back in there? What does it do?
Anyway the code above I copied from a client that has been using it for many years without a problem, so not sure what the issue is.
You're right. I only need the FORMAT function on cust."No." because it is a code.0 -
I am pretty sure you can add code to text, just not the other way around without an UPPERCASE in there.David Singleton0
-
I had this problem and I solved it : in the CUSMTP.CreateMessage call, the last parameter (htmlformatted) must be FALSE. Then the string CRLF works.0
-
I've upgraded a customers NAV from NAV2013R2 to NAV2017 and now I had to change the code for CRLF.
It was:
ch13 := 13;
lf10 := 10;
EXIT(FORMAT(lf10) + FORMAT(ch13));
This stopped working in NAV2017 with Outlook 2016.
So I used David's solution:
CRLF[1] := 13;
CRLF[2] := 10;
EXIT(CRLF);
It works again.
Tino Ruijs
Microsoft Dynamics NAV specialist0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions