Skip to content

How it Works

TRAML can be used to send emails or SMS from a custom limeobject, endpoint, task or event handler. All requests are sent synchronously and you will get an instant feedback if your message could be sent to Lime Marketing.

Email

This guide will walk through how to use TRAML from a custom limeobject.

Step 1: Import and initialize the library

Inside your-addon-folder/limeobject_classes/object.py import the library and the Email model:

from limepkg_transactional_message_library.traml import Traml
from limepkg_transactional_message_library.models import Email

Step 2: Creating the Email model

Inside the limeobject class, create the Email model in the after_update method:

email = Email(
    recipient_name=self.properties.firstname.value,
    recipient_email=self.properties.email.value,
    from_name='Lime',
    from_email='[email protected]',
    subject='Here is a transactional email!')

The properties for an Email are:

Parameter Name Type Default Value Description
recipient_name string The name of the recipient
recipient_email string The email address of the recipient
from_name string The name of the author
from_email string The email address of the author
subject string The subject
sender_name string None The name of the sender
sender_email string None The email address of the sender
attachments string [] A list of attachments. Read more here
merge_codes string {} A dictionary containing merge codes
options string {} A dictionary for optional parameters

Optional properties for an Email:

Parameter Name Type Default Value Description
external_id string Bind the email message to an external id (a Marketing Activity for example).
track_openings bool False Should message openings be tracked.
track_link_clicks bool False Should link clicks be tracked.
send_datetime datetime None (the message will be sent ASAP) Date and time if you want to delay the message.
reply_to string None Set a reply to email address to your message.

Step 3: Create a Traml instance and send the email

TRAML can send the Email either by a template id or with a HTML content. The template id can be found in Lime Marketing (TODO: instert image of template archive)

instance = Traml(self.application)
send_result = instance.send_transactionmail_by_template(template_id=123, message=email)

The send_result will be a SentTransactionMailModel if the Email was sent successfully to Lime Marketing. If something went wrong it will be None and any errors will be logged to the error log.

!!!info: The Traml constructor can be initialized with a custom SendContext, Validator and application config

Step 4: Profit 🥇


SMS

If the SMS module is actived in Lime Marketing TRAML can be used to send SMS.

To send SMS use the SMS model and send the message:

from limepkg_transactional_message_library.models import Sms

sms = Sms(
    text='This is a transactional SMS',
    from_number='Lime',
    destination_number='+46701234567'
)
instance = Traml(self.application)
send_result = instance.send_sms(sms_message=sms)

Validation

TRAML will automatically validate Emails and SMS to ensure deliverability. TRAML uses the same

Back to top