can not create multi line email body

darshanmdarshanm Member Posts: 280
Hi,

I am generating email from Navision code unit MAIL.
I am facing problem while creating email body.

I am using newmessage() function to send the mail, But
I can not format the body of the email.

Please let me know how to use Mail.AddBodyLine()
function.
Darshan Mungekar
Senior Consultan

Comments

  • Revolution1210Revolution1210 Member Posts: 161
    You can generate your new lines as follows, where CR is a Char type variable.
    CR := 13;
    ..
    ..
    Mail.AddBodyline('body line 1' + FORMAT(CR)) ;
    Mail.AddBodyline('body line 2');
    ..
    ..
    
    Ian

    www.NextEqualZero.com
    A technical eye on Dynamics NAV
  • darshanmdarshanm Member Posts: 280
    Hi,

    I am writing below code in one of the report, which directly
    sends an email to user. please tell me where to put code for
    Mail.AddBodyline('body line 2');


    Body := Item.Description + FORMAT(ValueEntryBuffer."Invoiced Quantity");
    .....
    ......
    Mail.NewMessage(SalesReceivablesSetup."Item Notify To",'','Item Sales Qty',Body,'',FALSE);
    Darshan Mungekar
    Senior Consultan
  • darshanmdarshanm Member Posts: 280
    Any help on this....
    Darshan Mungekar
    Senior Consultan
  • MalajloMalajlo Member Posts: 294
    Try with AddBodyline(TextLine : Text[260]). But you are limited to 260 chars for mail body.

    You will have to split code in NewMessage where body is appended.
    IF ISCLEAR(BSTRConverterBody) THEN
      CREATE(BSTRConverterBody);
    
    IF Body <> '' THEN BEGIN
      BSTRConverterBody.ResetBSTR;
      BSTRConverterBody.AppendNextStringPortion(Body);
    END;
    OSendMail.Body := BSTRConverterBody;
    

    I.e. for only one new-line:
    IF Body <> '' THEN BEGIN
      BSTRConverterBody.ResetBSTR;
      if strpos(body,'\') <> 0 then
        begin
          appendnextstringportion(copystr(body,1,strpos(body,'\'));
          appendnextstringportion(copystr(body,strpos(body,'\')+1,260);
        end
      else BSTRConverterBody.AppendNextStringPortion(Body);
    end ;
    
  • bakshibakshi Member Posts: 10
    hi,

    i m also facing the same problem.
    i hv put folloeing code in function NewMessage in codeunit mail:
    I.e. for only one new-line:
    Code:
    IF Body <> '' THEN BEGIN
    BSTRConverterBody.ResetBSTR;
    if strpos(body,'\') <> 0 then
    begin
    appendnextstringportion(copystr(body,1,strpos(body,'\'));
    appendnextstringportion(copystr(body,strpos(body,'\')+1,260);
    end
    else BSTRConverterBody.AppendNextStringPortion(Body);
    end ;


    but in this fuction above of this code there are couple of lines:


    IF (NOT OApplication.Logon(TRUE,'','',FALSE,FALSE)) THEN BEGIN
    OApplication.Logoff;
    EXIT
    END;

    this is the fourth line in this function. From here Exit function is working and my remaining function is not executing.
    plz suggest something.
    Bakshi Bilochi
  • darshanmdarshanm Member Posts: 280
    any more inputs on this problem???
    Darshan Mungekar
    Senior Consultan
  • todrotodro Member Posts: 117
    darshanm wrote:
    any more inputs on this problem???
    Is outlook started ? The codeunit expects an existing outlook instance.

    You can try changing the code to look like this:

    Old:
    IF (NOT OApplication.Logon(TRUE,'','',FALSE,FALSE)) THEN BEGIN
    

    New:
    IF (NOT OApplication.Logon(FALSE,Profilename,MailPW,FALSE,FALSE)) THEN BEGIN
    
    or
    IF (NOT OApplication.Logon(FALSE,Profilename,MailPW,FALSE,TRUE)) THEN BEGIN
    

    where profilename is the name of the outlook profile and MailPW the appropriate password. But beware of the security issue when setting a hardcoded plaintext password!
    Torsten
    MCP+I, MCSE NT, Navision MCT (2004,2005)
  • darshanmdarshanm Member Posts: 280
    my Outlook is running and navision sends email to the user perfectly.
    But i want to create a email body with multi line, which i am not
    able to do...
    Darshan Mungekar
    Senior Consultan
  • AlbertvhAlbertvh Member Posts: 516
    Hi
    Have you tried it like this
    Body := Item.Description + FORMAT(ValueEntryBuffer."Invoiced Quantity"); 
    Mail.AddBodyLine(Body);
    Mail.AddBodyLine('Regards,');
    
    Mail.NewMessage(SalesReceivablesSetup."Item Notify To",'','Item Sales Qty','','',FALSE);
    


    Albert
  • todrotodro Member Posts: 117
    darshanm wrote:
    my Outlook is running and navision sends email to the user perfectly.
    But i want to create a email body with multi line, which i am not
    able to do...
    sorry, this was meant as a reply to bakshi's post
    Torsten
    MCP+I, MCSE NT, Navision MCT (2004,2005)
  • bakshibakshi Member Posts: 10
    hi,

    i hv used this code also but still all the data is going in single line in body.

    plz suggest something else.
    Bakshi Bilochi
  • jlandeenjlandeen Member Posts: 524
    Have you tried inserting the Cariage Return & Line Feed characters manually?

    I had to do some testing for a project with sending emails, but that piece was scrapped. So I had the same problem and I never got around to trying it by passing through those characters manually. It may be worth a try.
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • todrotodro Member Posts: 117
    bakshi wrote:
    hi,

    i hv used this code also but still all the data is going in single line in body.

    plz suggest something else.
    so I understand, the exit is no longer a problem.

    For the linefeed, simply add the CRLF like this:
    IF Body <> '' THEN BEGIN
      CR := 13;
      LF := 10;
      BSTRConverterBody.ResetBSTR;
      IF STRPOS(Body,'\') <> 0 THEN
        BEGIN
          BSTRConverterBody.AppendNextStringPortion(COPYSTR(Body,1,STRPOS(Body,'\')-1) + FORMAT(CR) + FORMAT(LF));
          BSTRConverterBody.AppendNextStringPortion(COPYSTR(Body,STRPOS(Body,'\')+1,260));
        END
      ELSE BSTRConverterBody.AppendNextStringPortion(Body);
    END ;
    
    Torsten
    MCP+I, MCSE NT, Navision MCT (2004,2005)
Sign In or Register to comment.