Jun 29

Just a quick post here serving as shortcut for implementing Microsoft Navision Mail.SmtpMessage in older databases. All it requires is these objects:

  • Table 409 SMTP Mail
  • Form 409 SMTP Mail
  • Codeunit 400 SMTP Mail

And of course an updated license file for the customer, that adds the permissions for the new 5.0 objects. If they are not on the v5 executables they also need to install the “Microsoft.Navision.Mail.dll” automation control. I have created a small package here that is a selfextracting rar file, that automatically installs the component into the Global Assembly Cache.

Here are the objects (from 5.0SP1):

[dm]6[/dm]

And the Mail automation installer:
[dm]5[/dm]

Usage is very simple:

SMTP.CreateMessage(SenderName,SenderAddress,Recipients,Subject,Body,HtmlFormatted);
SMTP.Send();

you will see methods for AddRecipients, AddCC, AddBCC, AppendBody and AddAttachment. The component also supports HTML in the body section.

Update 6/29/2010:

I just received a message from my danish colleague Steffen Brandt, that a hotfix is available from Microsoft, that allows you to change the standard SMTP port 25. The KB981354 has the information. I will update the download section tomorrow, so it has the latest DLL’s and fob’s.

Hotfix code changes:

Add column 6 in the SMTP Mail Setup table(409) as follow:

...
{ 6   ;   ;SMTP Server Port    ;Integer       ;InitValue=25; }
...

4.	Add the SMTP Server Port field in the SMTP Mail Setup form(409) as follow:

...
{ 14  ;TextBox      ;3850 ;1540 ;5500 ;440  ;Name=<SMTP Server Port>;
                                                 ParentControl=1;
                                                 InPage=0;
                                                 DecimalPlaces=0:0;
                                                 NotBlank=Yes;
                                                 Numeric=Yes;
                                                 SourceExpr="SMTP Server Port";
                                                 MinValue=1 }
    { 15  ;Label        ;440  ;1540 ;3300 ;440  ;ParentControl=14; }
...

5.	Change the code in the SMTP Mail codeunit(400) as follows:
Existing code 1

...
      Mail@1000 : Automation "{68AEAA7B-9523-3511-AF5F-F2381D2C6F04} 1.0:{F9DAE2A4-D2F8-37C3-86D5-E4FFE166D860}:'Microsoft Navision Mail'.SmtpMessage";
...

Replacement code 1

...
      Mail@1000 : Automation "{68AEAA7B-9523-3511-AF5F-F2381D2C6F04} 7.0:{F9DAE2A4-D2F8-37C3-86D5-E4FFE166D860}:'Microsoft Navision Mail'.SmtpMessage";
...



Existing code 2

...
                Mail.Send(
            "SMTP Server",Authentication <> SMTPMailSetup.Authentication::Anonymous,"User ID", Password);
...

Replacement code 2

...
                Mail.Send(
            "SMTP Server",Authentication <> Authentication::Anonymous,"User ID",Password,"SMTP Server Port");
...

29 Responses to “SMTP Mail functionality in Pre Dynamics NAV 5 versions”

  1. Les Mclauglin says:

    I saw this blog through Facebook (someone posted it). After reading, I then clicked “Like” and shared it.

  2. Mikki Feldman says:

    This is my first time I have visited here. I found a lot of interesting information in your blog. From the volume of comments on your posts, I guess I am not the only one! keep up the good work.

  3. Subrata Bauri says:

    I am using this, but could not send any smtp (smtp.gmail.com). It gives me following error message :

    “ The SMTP mail system returned the folloeing error message: The SMTP server requires a secure connection or the client was not Authenticated. The server response was:5.7.0 Must issue a STARTTLS command first. b11sm2417142rvf.10 “

    Kindly help me to solve it ?

    Thank you.

  4. Mads Morre says:

    Hi
    Brilliant solution, but…

    When you specify your Body section the danish characters ‘æøå’ isn’t allowed – ‘?’ is shown instead.
    The Subject part can handle these characters, so what am i doing wrong?

    Regards
    Mads Morre

  5. Mads you would have to write a function HTMLEncode(BodyText) that would do the encoding for you. It would basically search for you national chars, and replace them with the HTML encoded string. Pretty simple.

    • Mads Morre says:

      Hi Søren
      I am not quite clear on what you mean. How can i change the way this function handles the danish characters?

      As i said, both subject and body contains these characters, but subject can handle them – body can’t.

      Regards
      Mads

  6. […] is replacing a special char with a new string value. This example came from the previous post on SMTP Mail functionality in Pre Dynamics NAV 5 versions. Mads from Denmark, ran into an issue with HTML encoding when using national chars like: […]

  7. Mads Morre says:

    Hi Søren

    Thank You very much! – I can make it work now.
    But can you tell me one thing – why is it that, when i use this SMTP-function in Nav 2009 using Automation Microsoft.Navision.Mail instead of Microsoft.Dynamics.Mail Helper (the one you have provided) then it handles these danish characters. Is it the Automation that are written to understand these characters (my appologies for asking these questions, but i am new to these parts of developing)?

    Regards

    Mads Morre

  8. […] is replacing a special char with a new string value. This example came from the previous post on SMTP Mail functionality in Pre Dynamics NAV 5 versions. Mads from Denmark, ran into an issue with HTML encoding when using national chars like: […]

  9. Vicky dada says:

    Friends, I have installed the application and deleted the installed folder, now I get the message “The message is for C/AL programers” could not invoke the member send. The OLE control or Automation server returned an unknown error”

    I have used in NAV 2009 SP1

  10. […] SMTP mail functionality in pre V5 How to install and use SMTP mail in older version of NAV. […]

  11. Mark says:

    Tried to use this functionality and receive:
    Could not invoke the member Send. The OLE control or Automation server returned an unknown error code.

    I’ve tried ion all authentication types with the same result. Any ideas?

  12. Check the Send() function in codeunit 400:

    WITH SMTPMailSetup DO
    Result :=
    Mail.Send(
    “SMTP Server”,Authentication SMTPMailSetup.Authentication::Anonymous,”User ID”, Password);
    CLEAR(Mail);
    IF Result ” THEN
    ERROR(Text003,Result);

    In the newer versions it also requires a parameter for the port no. to send.

    So you need a version 5 codeunit to work with the old SMTP mail, and 2009 with the hotfix in to work with the new SMTP.

    Let me know if this solves it, or i can post the codeunits in the download section too.

    • Mark says:

      Thanks Soren. I downloaded the objects and dlls you have above and installed on my 4.00 SP2 system. Is there an updated CU needed? I would appreciated an updated version if you have it.
      Many Thanks!

  13. Yeah, the latest DLL is for version 2009. It has the port no. for the SMTP.Send method included, and also the fix for the file locking.

    Do you have access to designing the codeunit, then you can change the automation and the Send method yourself. If not let me know, and i can upload a version 4SP2 codeunit with the changes.

  14. Mark says:

    Yes I do have access to designing Codeuntis however I couldn’t find the correct Automation type. I see one called “Microsoft Dynamics NAV Mail Helper which has IMessage and SmtpMessage Classes. Not sure if that is correct?

  15. Mark says:

    Never mind, I got it working. I used the Automation mentioned above added the port 25 and all is good now! Thank you very much!

  16. Mahmoud says:

    ok I created another table and modified the form because of a license problem and changed the Automation Server, anyway when I run my method which is
    Mail.Send(
    “SMTP Server”,Authentication Authentication::Anonymous,”User ID”,Password,”SMTP Server Port”);

    SendMailCU.CreateMessage(‘me@mycomany.com’, ‘me@mycompany.com’, ‘me@mycompany.com’,
    ‘me@mycompany.com’, EMailBody, TRUE);

  17. Mads Morre says:

    Hi

    Maybe a “beginner” Question, but how do I uninstall the Dynamics Nav Mial Helper function again.
    We Use 2 diff. versions of Navision. Inside my house we use 4.0 and my external customers use Nav 2009. I work (as developer) in both solutions.
    Now after installing The Nav Mail Helper for the 4.0 solution, i can’t send a mail from the Nav 2009 client.
    Can I uninstall the Dynamics Nav Mail Helper .dll again?
    regards
    mads morre

  18. Sherry says:

    I am not able to send mail through smtp (smtp.gmail.com). It gives me following error message :

    “ The SMTP mail system returned the folloeing error message: The SMTP server requires a secure connection or the client was not Authenticated. The server response was:5.7.0 Must issue a STARTTLS command first. b11sm2417142rvf.10 “

    Kindly help me to solve it ?

    Thank you.

    • Sami says:

      Hi Sherry,
      I have solution for SMTP Server as smtp.gmail.com and its working 100%.If you are really interested reach me at sami.3187@gmail.com

      Thanks,
      Sami Mohammed,
      Navision Technical Consultant.
      Microsoft certified professional

  19. Chowdary says:

    Thanks a lot SNielsen!

    Mark says:
    February 16, 2011 at 04:56

    Never mind, I got it working. I used the Automation mentioned above added the port 25 and all is good now! Thank you very much!

    this post helped 🙂
    thanks Mark

  20. Denis says:

    Hi there Soren!

    I installed your objects on our 4.00SP2 (5.0 SP1) NAV, tested it and it worked as a charm.

    After a couple of hours, the thing just stopped working and now all I get is “can’t invoke Send” message…

    Any ideas?

  21. Denis says:

    Hey there!

    I solved the problem. In CU 400 I changed Mail automation to ‘Microsoft Dynamics NAV Mail Helper’.

    It want the user to add port number (which in my case is 25).

    The reason why previous automation stopped working is still unknown…

  22. Gaurav says:

    am not able to send mail through smtp (smtp.gmail.com). It gives me following error message :

    “ The SMTP mail system returned the folloeing error message: The SMTP server requires a secure connection or the client was not Authenticated. The server response was:5.7.0 Must issue a STARTTLS command first. b11sm2417142rvf.10 “

    Kindly help me to solve it ?

  23. Sanusi says:

    Pls, the File Microsoft.Navision.Mail7.exe could not be downloaded. Help send a copy directly to sanusigreat@gmail.com.

    Kind regards

    Sanusi

Leave a Reply to Les Mclauglin

preload preload preload
pornpants.com pornofri.com kilporn.com