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.
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.
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;
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;
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.
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]
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
a table with SMTP fields
‘Microsoft CDO For Exchange 2000 Library’.Configuration
‘Microsoft CDO For Exchange 2000 Library’.Message
‘Microsoft ActiveX Data Objects 2.5 Library’.Fields
‘Microsoft ActiveX Data Objects 2.5 Library’.Field
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…