Return Value in Mail Codeunit

rkaufmannrkaufmann Member Posts: 71
edited 2007-07-25 in Navision Financials
Hello,

has anybody an idea, how to modify CU 397 "Mail" in NAV 2.60 to create a return value, that display me, whether a mail was successfully send or not.

It would be extremly helpful for me to have control over the code execution, to react on the result of the mail send action.

Because sometimes our mailserver is busy and then the mail send is not successful, but my code continues as if it was successful.

Regards,
Rolf

Comments

  • todrotodro Member Posts: 117
    rkaufmann wrote:
    Hello,

    has anybody an idea, how to modify CU 397 "Mail" in NAV 2.60 to create a return value, that display me, whether a mail was successfully send or not.

    It would be extremly helpful for me to have control over the code execution, to react on the result of the mail send action.

    Because sometimes our mailserver is busy and then the mail send is not successful, but my code continues as if it was successful.

    Regards,
    Rolf
    Hi,

    an untested suggestion:

    use return value type boolean

    add an exit at the end of function "NeuMitteilung" with the sent parameter

    ...
    IF ÖffneDialog THEN
      MAPIMitteilungen.Action(2) // SendeDialog
    ELSE
      MAPIMitteilungen.Action(3); // Senden
    
    EXIT(MAPIMitteilungen.MsgSent)
    
    Torsten
    MCP+I, MCSE NT, Navision MCT (2004,2005)
  • rkaufmannrkaufmann Member Posts: 71
    Hi,
    MAPIMitteilungen.MsgSent
    

    always returns "FALSE".

    I think this is not designed to return the success-message for sending an Email.
  • todrotodro Member Posts: 117
    rkaufmann wrote:
    Hi,
    MAPIMitteilungen.MsgSent
    

    always returns "FALSE".

    I think this is not designed to return the success-message for sending an Email.
    I examined the MAPI control with the following result:

    it seems that the property msgsent is not set at all. Digging through the docs I found one of the reasons to be the msgindex, which has to be -1 for the outgoing buffer, nevertheless it does not work. It maybe related to the asynchronous transmission from the outlook client to the exchange server.

    I verified that it is possible to catch all the outlook related errors when using the OCX outside Navision (as Navision doesn't support structured or global error handling). So it is possible to detect e.g. if the user canceled the sending request when using the interactive variant of the send method etc. In case everything is fine, the error code is 0.

    I need to find a way to simulate the busy server to see whether this error is caught too. If so, I'll create an OCX-wrapper. Let me know whether you would like to test it.
    Torsten
    MCP+I, MCSE NT, Navision MCT (2004,2005)
  • rkaufmannrkaufmann Member Posts: 71
    Hi,

    yes I would like to test, if you manage to create that wrapper.

    By the way, we don't use Outlook or Exchange. We use a Mailsystem called "David".
  • todrotodro Member Posts: 117
    rkaufmann wrote:
    Hi,

    yes I would like to test, if you manage to create that wrapper.

    By the way, we don't use Outlook or Exchange. We use a Mailsystem called "David".
    Hi,

    a first version can be downloaded here http://www.todro.de/MapiWrapperForNavision.msi

    I made it compatible to the properties and methods of Navision 3.70B's codeunit 397.

    This is an extract from the codeunit:
    OnRun()
    NewMessage('torsten','','Subject - Test','BodyLine #1','c:\boot.ini',FALSE);
    MESSAGE('Error: %1',ErrorNo);
    
    
    NewMessage(ToName : Text[80];CCName : Text[80];Subject : Text[260];Body : Text[260];AttachFileName : Text[260];OpenDialog : Boolean) Ma
    IF ISCLEAR(MAPIHandler) THEN
      CREATE(MAPIHandler);
    
    ErrorNo := 0;
    MAPIHandler.ToName := ToName;
    MAPIHandler.CCName := CCName;
    MAPIHandler.Subject := Subject;
    IF Body <> '' THEN
      MAPIHandler.Body := Body;
    
    MAPIHandler.AddBodyText('Test Bodyline #2');
    
    MAPIHandler.AttachFileName := AttachFileName;
    MAPIHandler.OpenDialog := OpenDialog;
    
    MailSent := MAPIHandler.Send;
    ErrorNo := MAPIHandler.ErrorStatus;
    
    

    Any feedback appreciated.
    Torsten
    MCP+I, MCSE NT, Navision MCT (2004,2005)
  • rkaufmannrkaufmann Member Posts: 71
    Hi,

    thanks for the Tool.

    I installed it an did some testing.
    So far I found no problems and it works really good.

    I have just on question:
    What is the max. Characters that the following methods and properties can handle?
    - ToName
    - CCName
    - Subject
    - Body
    - AttachFileName
    - AddBodyText


    I just integrated it into my application, and tomorrow I will give you more feedback, if your MAPI Wrapper is stable.

    Thanks,
    Rolf
  • todrotodro Member Posts: 117
    rkaufmann wrote:
    Hi,

    thanks for the Tool.

    I installed it an did some testing.
    So far I found no problems and it works really good.

    I have just on question:
    What is the max. Characters that the following methods and properties can handle?
    - ToName
    - CCName
    - Subject
    - Body
    - AttachFileName
    - AddBodyText


    I just integrated it into my application, and tomorrow I will give you more feedback, if your MAPI Wrapper is stable.

    Thanks,
    Rolf
    Hi Rolf,

    max. strlen is actually 1024. As Navision 2.x supports a maximum length of 256(250) only, this might be a problem but only for properties maintained by the wrapper (ErrorDescription) and might cause an overflow when getting a longer error description. I will change the behaviour like this and create a new version:

    a.) max. strlen for the check (and copy) can be set from Navision
    b.) error description can be retrieved on a line-by-line basis with a max. length as defined with a.)

    So far, I did not check explicitly the max. length MAPI accepts. This is an open task but nevertheless, any error will be reported in the error status so I do not see a problem here. The only thing is that the error might not be as "speaking" as it could be, but working with Navision we have arranged with this type of error messages :mrgreen:

    Regards,

    Torsten
    Torsten
    MCP+I, MCSE NT, Navision MCT (2004,2005)
  • rkaufmannrkaufmann Member Posts: 71
    To make things more clear:

    We are running on NAV 4.0 SP2 on SQL 2005, but we use the functions from the 2.60 CU 397, because in 2.60 this CU was MAPI compatible, while the Version in 4.0 of this CU only works with Outlook.

    So we don't underlie the restrictions of 2.60, but we are currently using the Mail CU from 2.60 because we don't use Outlook at the moment.
  • rkaufmannrkaufmann Member Posts: 71
    Hi,

    I'm using the tool now for two days in our productive environment, without any problems.

    Just one more question:
    Is it posible to have more than one attachment in an email with our tool?

    Thanks again,
    Rolf
Sign In or Register to comment.