eDoreczenia_SendSingleMessage
The eDoreczenia_SendSingleMessage() function initiates a process of sending message with a specified content to a single receiver within e-Delivery system. There are available two main options of shipping services:
- ’electronic’ – via PURDE service (digital transfer);
- ’hybrid’ – via PUH service (a message is converted to a traditional paper letter and delivered by the postal service).
Syntax
eDoreczenia_SendSingleMessage(mailboxId, messageSettings, messageContent);
Function arguments
- mailboxId – (String) an identifier of the mailbox on behalf of which the message will be sent (mailbox of the sender). Mailbox has to be registered in AMODIT with unique id;
- messageSettings – (Object) the set of settings that defines the way the message will be sent (i.e. list of receivers, electronic or hybrid shipping, and other options). The presented settings are in major part the same as the settings described in the UserAgent API documentation (provided by e-Delivery);
- messageContent – (Object) this argument allows to estabilish the content of the message (i.e. subject, text body and list of attachments).
Return value
The eDoreczenia_SendSingleMessage() function returns an Object type.
This object contains following properties:
- ’Success’ – returns True, if the operation succeeds;
- ’CombinedErrorMessage’ – returns description of an error in case of the operation failure;
- ’messages’ – list of messages sent to selected receivers (properties in message object: 'messageId’, 'AddresseeADE’ and 'status’).
Examples
Example 1
The example shows a universal way of preparing and sending message. The mentioned below code indicates the most common options that can be used in order to customize message sending.
// select from which mailbox message will be sent mailboxId = [mailboxId]; // choose type of shipping, two values available: 'electronic' or 'hybrid' messageSettings.shippingService = [shippingService]; // fill information about sender messageSettings.sender = { postalAddress: // set postal address of sender { country: [sender_country], street: [sender_street], postalCode: [sender_postalCode], city: [sender_city], buildingNumber: [sender_buildingNumber], houseNumber: [sender_houseNumber] }, contributorInfo: // set basic information about sender { // firstName and lastName are mandatory only if sender is a private person // (NOT company and NOT office), otherwise those two properties have to be empty firstName: [sender_firstName], lastName: [sender_lastName], // companyName and companyNameContinued are mandatory only if sender is a companny or an office // (NOT a private person), otherwise those two properties have to be empty companyName: [sender_companyName], companyNameContinued: [sender_companyNameContinued] } } // set options of hybrid shipping, they have to be set // only if 'hybrid' as shipping service is selected messageSettings.hybridShipment = { shippingMode: [shippingMode], // two available values: 'registered' and 'notRegistered' // five available values: 'general', 'administrative', 'tax', 'court_civil' and 'court_criminal' procedingType: [procedingType], // additional text that will be printed on the letter created from the message sendersInformation: [sendersInformation], categoryService: [categoryService], // two available values: 'economic' and 'priority' printingMode: [printingMode], // two available values: 'duplex' and 'simplex' overprintMode: [overprintMode], // two available values: 'monochrome' and 'color' returnService: [returnService], // two available values: 'returntosender' and 'destroy' proofOfDelivery: [proofOfDelivery], // boolean flag, true or false posteRestante: [posteRestante] // boolean flag, true or false }; //other settings // set reference to another message (by passing its id), determine the message // as the reply to the another message messageSettings.refToMessageId = [refToMessageId]; // set thread id, it allows to bind messages to specific conversation (thread) or create new one messageSettings.threadId = [threadId]; messageSettings.receiver = { // fill information about single sender // set postal address of sender, if shippingService has value 'hybrid', then property if mandatory postalAddress: { country: [receiver_country], street: [receiver_street], postalCode: [receiver_postalCode], city: [city], buildingNumber: [receiver_buildingNumber], houseNumber: [receiver_houseNumber] }, contributorInfo: // set basic information about single receiver { // firstName and lastName are mandatory only if the receiver is a private person // (NOT company and NOT office), otherwise those two properties have to be empty firstName: [receiver_firstName], lastName: [receiver_lastName], // companyName and companyNameContinued are mandatory only if the receiver is a companny or an office // (NOT a private person), otherwise those two properties have to be empty companyName: [receiver_companyName], companyNameContinued: [receiver_companyNameContinued] }, // set receiver's e-Delivery address, it has to be set // if shippingService has value 'electronic' eDeliveryAddress: [receiver_eDeliveryAddress] } // setup message content // body (text content) of message can be set only for electronic shipping; // for hybrid shipping it should have empty value messageContent.body = [body]; messageContent.subject = [subject]; // set title (subject) of the message attachmentList = ''; // define variable which will store list of objects (representing files to send) foreachrow('attachments') // iterate through rows on table with attachments { if ([fileId] == '') { [fileId] = CreateGUID(); // generate unique id for file } attachment = { // define object which represents single file to send file: [file], // set file content by selecting Document-type field fileId: [fileId], // set file id filename: [filename] // set filename } // add object (file) into list of objects which is stored in variable 'attachmentList' AddObjectToList(attachmentList, attachment); } messageContent.attachments = attachmentList; // set list of files (objects) to send // execute rule function res = eDoreczenia_SendSingleMessage(mailboxId, messageSettings, messageContent); if (!res.Success) // check if operation is finished successfully { ShowMessage(1,res.CombinedErrorMessage); // in case of failure display reason of error }