Mail Codeunit (397) not sending NewMessage

I am using the Mail Codeunit to send an email from code.

I am calling the NewMessage function with the following parameters:

ToName = MyEmail
CCName = ‘’
Subject = ‘TEST’
Body = ‘This is a test’
AttachFileName = ‘’
OpenDialog = FALSE

The result is an email created and stored in my Drafts folder with the above parameters.

When I step through the code I get to

MailSent := OSendMail.Send;
ErrorNo := OSendMail.ErrorStatus;
OApplication.Logoff;

The result of this is MailSent = No and ErrorNo = 2731. I’m not really sure what that means.

Thanks in advance for you help.

As the email is in Draft folder, so the expected values are

MailSent = Yes (Email sent )and ErrorNo = 0 (No error).

Can you check it again, may be by adding a MESSAGE ?

Here is my updated code in Codeunit 397:

MailSent := OSendMail.Send;
ErrorNo := OSendMail.ErrorStatus;

//tempben
MESSAGE(‘MailSent = %1\ErrorNo = %2’,MailSent,ErrorNo);

It generated the following message:


Microsoft Dynamics NAV

MailSent = No

ErrorNo = 2731

OK

And if the email is in the drafts folder why would you expect the MailSent to be Yes? Shouldn’t it be in the Sent folder before that happens?

Try once by changing

OpenDialog = TRUE

It works. I get the following message:


Microsoft Dynamics NAV

MailSent = Yes
ErrorNo = 0

OK

But I need to be able to send emails without any further user prompts.

Hi Ben,

What version of Nav are you using?

…there was a problem with the outlook dll in pre-version 5 - to fix this the OLHandler.dll from the 5.0 SP1 client or greater should work.

I am running 5.0 SP 1.

If I needed to change/update the OLHandler.dll how would I do that?

One other thing: I have several users running this functionality on different machines, and they are getting different results.

For one it works as expected. Creates and sends an email to the designated people.

For another it is creating a draft email and not sending (same as my computer).

Is it possible that there is an issue with outlook or something?

Hi Ben,

Check the versions of Nav and outlook on each machine

The versions are exactly the same.

Hi Ben,

Try re-installing your Nav client