Labels

Showing posts with label .NET COM wrapper. Show all posts
Showing posts with label .NET COM wrapper. Show all posts

Saturday, July 9, 2011

Using LumiSoft.Net for retrieving e-mail from Dynamics NAV

Recently, I've found great library for net handling (POP, SMTP, FTP, HTTP and others) - LumiSoft.Net http://www.lumisoft.ee/lsWWW/download/downloads/Net/LumiSoft.Net.zip
Here is the link to the help index for that library http://www.lumisoft.ee/lswww/download/downloads/Net/Help/. Exciting!
It's open source (C# .NET) and completly free for modifing and using in commercial projects. Wonderfull, many thanks to it's author!
So, I was engaged in using this library in Dynamics NAV.

First of all, this library should be compiled as COM Automation object. For this possibility:
1) COM Interop on the project tab should be checked.
2) Special attributes for COM sharing should be appointed for the classes:
[ComVisible(true), ClassInterface(ClassInterfaceType.AutoDual),Guid(" ... ")]
Namespace System.Runtime.InteropServices should be used.
3) GUID for assembly should be appointed:
[assembly: Guid(" ... ")]
4) some classes should be redesigned (for example, static members are not visible in COM)

If Guids are not appointed that way, the linker automatically creates it, but every time you making changes in the source code you would have new Guids. It's too difficult for parallel NAV debugging, because C\AL variables are droped after new COM server is registered. The description "Unknown Automation Server.Unknown Class" is shown in that case.
I used special tool for Guid creation (Tools - Create Guid in Visual Studio).

In Dynamics NAV I've created a pair of simple tables (Message and Mailbox). Message have a table relation to Mailbox:

Wednesday, June 22, 2011

Using .NET COM object for sending e-mails or SMS in NAV

As we all know standard MAPI interface, provided in NAV, works only when mail client (like Outlook Express or Outlook) is installed. There are several issues why this approach is not suitable. I decided to develop my own COM object to work directly with SMTP server.

My .NET COM wrapper for System::Net::Mail::SmtpClient consist of 3 main files:

  • SMTPClient.idl - interface definition;
  • SMTPMessage.h - header file;
  • SMTPMessage.c - source code;
New .NET COM class should provide methods to define parameters:
  • Sender e-mail address & sender name (shown in message, field From);
  • Receiver e-mail address & receiver name (shown in message, field To);
  • Server name, port and flag for using SSL protocol;
  • User name & password for authentication.
Total source project directory you can download here: https://sites.google.com/site/9ri331y/SMTPClient.sources.zip


Please, post a feedback if you find this project useful for you.

SMTPClient.idl list:

// SMTPClient.idl : IDL source for SMTPClient
import "oaidl.idl";
import "ocidl.idl";