How to send smtp mail from Navision 4.0

I would like to send a mail through smtp (using NAS).

I would prefer not to install any external components just use a Navision component and specify the smtp server and send the message.

Anybody knows if navision has a standard component for this and the commands ??

Hm, with an external, really nice ocx it is doable. Check out this or this.

I dont believe an navision email component exists to do what you are asking, so i think it will have to be an external one.

This may or may not be relevant but if you intend to have an email body with more than text than navision the internal buffer size can handle (255 chars in 2.60 and below, 1024 in 3.01 +, not sure about v4+) I would use one which allowed you to use the content of a text file as the email body, this would obviously require you to write the content to a temporary text file first but would not restrict you in email body length.

There are some nice and simple smtp components on the web that would probably do the job you need.

Hi,

You don’t need to install anything because SMTP is a network service native to Windows. You simply add two OCXs as C/AL Global Variables:

  • Microsoft MAPI Messages Control, version 6.0
  • Microsoft MAPI Session Control, version 6.0

Navision is only an application running on top of all these Windows and network services. Though you could use Outlook Object Model to achieve the same, I would suggest that you stick w/ Windows native service.

However you will always get this warning: “A program is trying to automatically send e-mail on your behalf. Do you want to allow this?” and there is no way to turn it off. You can learn more about MAPI in Microsoft KB and MSDN.

Scott

I have used the MAIL codeunit to send email. However, I need a session with outlook to send email. But the result is okay.

Richard

I finally ended up sending smtp directly from navision just using standard MS components

and it works fine and do not prompt if you want to send mail and do not need outlook client installed but going directly on the smtp server.

Would it be possible to get information on the defined variables and a (anonymized) code piece?

Below is the function wich allows you to send an e-mail via SMTP. You can use it without outlook session and it works when navision is running as service (application server) and also does not require user to press “Yes” in allow-to-use-mail-box dialog :). Enjoy!:

function NewCDOMessage(ToName : Text[80];Subject : Text[260];Body : Text[1024];AttachFileName : Text[260])

// recSetup – a table with SMTP fields
// objEmailConf – ‘Microsoft CDO For Exchange 2000 Library’.Configuration
// objEmail – ‘Microsoft CDO For Exchange 2000 Library’.Message
// flds – ‘Microsoft ActiveX Data Objects 2.5 Library’.Fields
// fld – ‘Microsoft ActiveX Data Objects 2.5 Library’.Field

recSetup.GET;
recSetup.TESTFIELD(“SMTP Server Name”);
recSetup.TESTFIELD(“SMTP Server Port”);
recSetup.TESTFIELD(“E-Mail From”);
IF ISCLEAR(objEmailConf) THEN
CREATE(objEmailConf);
flds := objEmailConf.Fields;

fld := flds.Item(‘http://schemas.microsoft.com/cdo/configuration/smtpserver’);
fld.Value(recSetup.“SMTP Server Name”);

fld := flds.Item(‘http://schemas.microsoft.com/cdo/configuration/smtpserverport’);
fld.Value(recSetup.“SMTP Server Port”);

fld := flds.Item(‘http://schemas.microsoft.com/cdo/configuration/sendusing’);
fld.Value(2);

flds.Update();

IF ISCLEAR(objEmail) THEN CREATE(objEmail);
objEmail.Configuration := objEmailConf;
objEmail.From := recSetup.“E-Mail From”;
objEmail.“To” := ToName;
objEmail.Subject := Subject;

IF Body <> ‘’ THEN
objEmail.TextBody := Body;
IF AttachFileName <> ‘’ THEN
BEGIN
objEmail.AddAttachment(AttachFileName);
IF Body=’’ THEN
objEmail.TextBody :=’ ';
END;

objEmail.Send;

If you want to have an e-mail body longer that 1024 character, use objEmail.AddRelatedBodyPart(AttachFileName,‘0’,0) method in order to attach file like body part, not like ordinary attachment. The file might be html or txt.

Have fun!

Thanx a lot!

I have not checked out the standard SMTP features which are now shipped in NAV 5.0

Is it possible now possible to send a mail with HTML content embedded in the body “out-of the box”, that’s without using any 3rd party component

(I’m not talking about file attachment here but a mail body in HTML)

yes you can.

Hello Muno,

How would you do that, I did check CU400 and I’ve not found the property which allows me embedding my HTML file into the body

I tried this :

CLEAR(CU400);

// CU400.CreateMessage(SenderName,SenderAddress,Recipients,Subject,Body,HtmlFormatted)
CU400.CreateMessage(‘test@mydomain.com’,‘test@mydomain.com’,'mybizpartner@foo.com,‘SUBJECT’,
‘C:\MYDOC.HTM’, TRUE);
CU400.Send;

BTW : MYDOC.HTM links to some pictures and logos

You should load file in a text and by parts you should use AppendBody function

Tried this and works perfect when I send locally [:D]

Just one little problem, when I send outside I’m getting the following error

The call to member failed. Unknown Class returned the following message: The server rejected one or more recipient addresses. The server response was: 550 5.7.1 Unable to relay for [e-mail]

Problem fixed, we had to setup some relaying options on our Domino server. Everything seems to be working fine.

Thanks all.

Dear Justas Janauskas,

I am new in navision 4.0 I dont know more aboute navision code, bt i wann send report as attachment to mail through navsion, i hv seen your code bt i am not understanding how to difine following variables.

// recSetup – a table with SMTP fields
// objEmailConf – ‘Microsoft CDO For Exchange 2000 Library’.Configuration
// objEmail – ‘Microsoft CDO For Exchange 2000 Library’.Message
// flds – ‘Microsoft ActiveX Data Objects 2.5 Library’.Fields
// fld – ‘Microsoft ActiveX Data Objects 2.5 Library’.Field

i mean to say which dll or ocx file i use to declare global variables.

i hv only following file in my Custom Control list

Name InprocServer32
Microsoft MAPI Messages Control, version 6.0 C:\Program Files\Common Files\Navision\Mapi\MSMAPI32.OCX
Microsoft MAPI Session Control, version 6.0 C:\Program Files\Common Files\Navision\Mapi\MSMAPI32.OCX

please tell me which dll or ocx file i should use for

  1. a table with SMTP fields
  2. ‘Microsoft CDO For Exchange 2000 Library’.Configuration
  3. ‘Microsoft CDO For Exchange 2000 Library’.Message
  4. ‘Microsoft ActiveX Data Objects 2.5 Library’.Fields
  5. ‘Microsoft ActiveX Data Objects 2.5 Library’.Field

Thanks

Sharad

sharad@ringplusaqua.co.in

I got great results with JMAIL.DLL automation.

The smtp sending is free, POP3 within Navision would cost some money.

Why?

hai Tarek Demiati…i try your code but i got one error message." SMTP Mail setup primary key does not exist"…then i try also AppendBody function to load txt or html file…so please help me…