Insert carriage return in smtp email body

tchanieltchaniel 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

Comments

  • David_SingletonDavid_Singleton Member Posts: 5,479
    Don;t use format, just add them in to the string

    test := 'This is line 1' + CRLF + 'This is line 2';
    David Singleton
  • David_SingletonDavid_Singleton Member Posts: 5,479
    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 Singleton
  • matttraxmatttrax Member Posts: 2,309
    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).
  • tchanieltchaniel Member Posts: 6
    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 + Char
  • tchanieltchaniel Member Posts: 6
    Also, I am using the SMTP Mail Codeunit(400).
  • David_SingletonDavid_Singleton Member Posts: 5,479
    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 Singleton
  • David_SingletonDavid_Singleton Member Posts: 5,479
    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 Singleton
  • tchanieltchaniel Member Posts: 6
    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.
  • David_SingletonDavid_Singleton Member Posts: 5,479
    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 Singleton
  • tchanieltchaniel Member Posts: 6
    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.
  • David_SingletonDavid_Singleton Member Posts: 5,479
    I am pretty sure you can add code to text, just not the other way around without an UPPERCASE in there.
    David Singleton
  • xinxoxinxo Member Posts: 5
    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.
  • tinoruijstinoruijs Member Posts: 1,226
    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 specialist
Sign In or Register to comment.