Microsoft.Navision.Mail.dll locks attachment file

lubostlubost Posts: 542Member
Hi everyone,

I have developed functionality to send sales documents by SMTP mail as PDF attachments. Everything goes fine, but when I want to delete sent files, Navision locks all sent files and these locks remains till Navision client has been closed. Then are files released and can be deleted (moved).
Environment:
NAV 2009 SP2 classic
Microsoft.Navision.Mail.dll version 7.0.0.0

What's wrong?

Thank you in advance

Comments

  • Luc_VanDyckLuc_VanDyck AartselaarPosts: 3,632Member, Moderator, Administrator
    Try putting a SLEEP(x) after the Send command to give NAV some time to send the mail and release the attachment. If you are always using the same filenames for your attachments, you can also delete them prior of creating them to get rid of the old ones.
    No support using PM or e-mail - Please use this forum. || Search is your friend
    NAV TechDays 2019: 21 & 22 November 2019, Antwerp (Belgium)
  • lubostlubost Posts: 542Member
    Thank you for your response.
    Files has unique filenames and are locked a hours ... exactly till Navision client has been closed.
  • Luc_VanDyckLuc_VanDyck AartselaarPosts: 3,632Member, Moderator, Administrator
    Are they saved in the TEMPORARYPATH folder?
    No support using PM or e-mail - Please use this forum. || Search is your friend
    NAV TechDays 2019: 21 & 22 November 2019, Antwerp (Belgium)
  • lubostlubost Posts: 542Member
    No, they are saved in "normal" path and till sending they are freely accesed (delete, move). But exactly attaching (or) sending file as attachment causes lock. Piece of code:

    Mail.SetHTMLBody(TRUE);
    Mail.AddAttachment(DocQueue."Document No." + '.PDF',
    CompanyInfo."Signed Folder" + DocQueue."Document No." + '_signed.pdf');
    WITH SMTPMailSetup DO
    Mail.SetConnectionParameters("SMTP Server", "SMTP Server Port", FALSE, TRUE, "User ID", Password);
    Result := Mail.SendMail();

    and mails are sent correctly, wihout any error.
  • ftorneroftornero Posts: 241Member
    That is a problem with Navision Mail version 7.0, you need to get the version 7.1 or 7.3 where there is a new method (Dispose) to free the atttachment after use the method Send.

    Regards,
  • lubostlubost Posts: 542Member
    Can you please drop a link where I can download these versions from?

    Thank you in advance
  • ftorneroftornero Posts: 241Member
    https://www.dropbox.com/s/ijsx07ymeg5g2 ... l.zip?dl=0

    You need to extract the files where are the previous version and execute the bat (register_for_com) as Adminstrator.

    You need to check the parameters in the Send method because they have changed from version 7.0.

    And add the method Dispose after Send in codeunit 400.

    Regards
  • lubostlubost Posts: 542Member
    Thank you ... DLL works as expected.
  • lubostlubost Posts: 542Member
    DLL doesn't locks attachments files but it uses domain authorization to send a mail withou respect to Send method parameters. I want to use this DLL to send PDFs by Navision Application Server (which need to run as domain user) and mailserver rejected message due to domain restrictions. SMTP setting is anonymous a all works fine in case of database login.
    I tried to manipulate with SMTP setting, but Anonymous, NTLM, Basic setting hasn't any effect with windows login.
    What's wrong?
  • ftorneroftornero Posts: 241Member
    That works for sure.

    Verify that the user that starts the NAS have the rights to send mail in your Mail Server.

    Regards.
  • lubostlubost Posts: 542Member
    Thank you for your reply.

    I don't want to send mail as user who starts NAS. I want DLL to use permission saved in SMTP Setup table. It seems that DLL uses domain permissions of logged user and don't use parametersfrom calling trigger:
    WITH SMTPMailSetup DO
    Mail.SetConnectionParameters("SMTP Server", "SMTP Server Port", FALSE, TRUE, "User ID", Password);

    I tried play with FALSE/TRUE parameters, but nothing changed.
  • ftorneroftornero Posts: 241Member
    Can you explain how you call to the DLL Send method, because the line below doesn't look like any method of this DLL ?

    >>>> Mail.SetConnectionParameters("SMTP Server", "SMTP Server Port", FALSE, TRUE, "User ID", Password);

    In version 7.3 this is the way:

    Mail.Send("SMTP Server", "SMTP Server Port", TRUE, "User ID", Password, FALSE);

    The TRUE is for authentication and the FALSE for enableSSL, this last can be changed if you uses SSL along with the Server Port.

    And you need to verify if your SMTP Mail Server allows that conection (user/password). You can use Outlook to configure the account and check it.
  • lubostlubost Posts: 542Member
    Thank you for reply.
    As I said, I played with FALSE/TRUE settings, but in all cases DLL uses the credentials of logged user (windows login) and never uses "User ID" and Password from SMTP setup.
    With version 7.3 of DLL I actually use the following approach:

    WITH SMTPMailSetup DO
    Result := Mail.Send("SMTP Server", "SMTP Server Port", Authentication = Authentication::NTLM, "User ID", Password, FALSE);

    but with Authentication set to Anonymous, NTLM or Basic - result is same - DLL logs to mail server with <domain>\<user> credentials.
  • ftorneroftornero Posts: 241Member
    So, I think that you must test your SMTP Mail Server with Outlook to verify if is possible to connect with that user/password combination, if that is the case then you can use the same with Authentication = Basic and the DLL.

    I tell you that because I'm using this in several installations and it's working without any problem.

    Regards
  • lubostlubost Posts: 542Member
    Thank you for your reply.
    We tested connection with manual request to send and all works fine, but we used database login during these tests. When we moved functionality under NAS (windows login), we discovered that DLL uses this login whatever SMTP setting. Connection is established and email are sent, but customer wants to disallow windows credentials to mail server (remote, provider based).
    Another problem is body encoding. Body is a HTML and this mail DLL uses UTF-16 encoding and on some mail servers/clients is content broken. Is the way to set encoding of HTML mail body?
  • ftorneroftornero Posts: 241Member
    You can use a remote provider with NAS, e.g. GMAIL or Office365 with the port 587 and SSL = TRUE and that work for sure, regarding the HTML body I don't think we have any control on this with the DLL.

    You can try 'Microsoft CDO for Windows 2000 Library'.Message and 'Microsoft CDO for Windows 2000 Library'.Configuration instead of the Navision Mail DLL.

    Regards.
  • Berno_SBerno_S Posts: 7Member
    @ftornero, should you by any chance still have the Navision Mail version 7.1 or 7.3 (the dropbox link is down)?
  • ftorneroftornero Posts: 241Member
    Hello @Berno_S ,

    Yes, I have the Navision Mail 7.3, here is the link with two 7.3 versions one newer than the other:

    https://www.dropbox.com/s/1cb1x4pqdp17zag/Mail_Dynamics_NAV2009R2_V7.3.zip?dl=1

    Regards
  • Berno_SBerno_S Posts: 7Member
    @ftornero great, all I need is to be able to change port, but the hotfix these files are a part of isn't available any more :(
  • Berno_SBerno_S Posts: 7Member
    @ftornero great, all I need is to be able to change port, but the hotfix these files are a part of isn't available any more :(
  • Berno_SBerno_S Posts: 7Member
    @ftornero upgraded the package but now it fails with "object reference not set to an instance of an object" when it comes to the setting to address, got any ideas? Google and mibuso suggests a hotfix older than the one i'm running already
  • ftorneroftornero Posts: 241Member
    Hello @Berno_S ,

    After register the new DLL you hae to change the Automation to the new version

    56kb7clnba13.png


    And then you have access to change the port

    yk3rg5sl3ctp.png

    For that you need to create the new field in the table or harcode the value.

    Regartds.
  • Berno_SBerno_S Posts: 7Member
    edited 2019-03-07
    This is all done, the error comes on executning the to statement
    dlplr2ltcj6t.png
    Btw I renamed the old variable to mail2, so it's the new variable i'm using
  • ftorneroftornero Posts: 241Member
    Hello @Berno_S ,

    The 7.3 version works, the error seems strange, maybe it is a conflict with the previous version.

    Try to install in a clean environment.

    Regards.
  • Berno_SBerno_S Posts: 7Member
    edited 2019-08-23
    ftornero wrote: »
    Hello @Berno_S ,

    The 7.3 version works, the error seems strange, maybe it is a conflict with the previous version.

    Try to install in a clean environment.

    Regards.

    Sorry for the late reply, but had to leave the assignment for some time for other projects, but now I got the server restarted and reregistered the new dll.
Sign In or Register to comment.