Guides

Sending mail

The v2 sending endpoints send a draft that you have created in the LianaMailer app. In the request, you choose the draft and who gets it, and you can override parts of the draft, such as the subject. The response contains the IDs you need to follow the delivery with the v1 endpoints.

Choose an endpoint

  • Event send (deliveries/event-send) sends a personal or transactional mail, such as an order confirmation, to the contacts in the request.
  • Batch send (deliveries/batch-send) sends a newsletter to mailing lists, to contacts in the request, or both.
  • Web page send (deliveries/webpage-send) sends a web page as a newsletter, in the same way as batch send.

All three can override the draft's letter.subject, letter.sender and letter.preheader_text. These fields, like letter.schedule and letter.ab, go inside letter. The same fields at the top level of the request are ignored, so a top-level schedule sends the mail right away.

The main differences between event send and batch send are:

deliveries/event-senddeliveries/batch-send
Sends toContacts in recipientsLists in lists, contacts in recipients, or both
WhenRight awayRight away, or at the time in letter.schedule
A/B subject testNot availableWith letter.ab
ContactsFound or created one by oneImported through a hidden list
CreatesOne event delivery for the draft, reused by each sendA copy of the draft, and a delivery for each list
ResendingFails, unless you allow itEach request is a new delivery
Responsedeliveries, mails and trackingid of the copy, deliveries and mails

Batch send delivers the mail to each contact only once, even if the contact is on several of the lists. An A/B subject test requires the A/B testing feature and open tracking, and cannot be combined with letter.schedule. It creates a delivery for each subject.

Web page send takes the same lists, recipients, letter.schedule and letter.ab as batch send, but gets its content from the web page at letter.url. It saves the page as a new draft and sends a copy of that draft. The subject is the page's <title>, unless you give letter.subject.

Before you send

Create and save the draft in the LianaMailer app, and give its ID in letter.id. Drafts with an A/B content test cannot be sent through the API.

Event send and batch send can also send SMS drafts, to the contacts' SMS numbers. The draft needs an SMS sender, and you can override the SMS text and sender with letter.sms and letter.sms_sender. Web page send sends only email.

The sender is letter.sender from the request if you give one. Otherwise it is the sender of the draft or its campaign, and failing that, the default sender in your account's delivery settings. The sender must be an email address or a property placeholder, such as $sender_email$.

The delivery uses the draft's site. Otherwise it uses the mailing list's site, and failing that, your default site. The site sets the address of the subscription pages that the mail links to. See getCustomerSites.

For event send, ask your Liana account manager to activate the transactional email feature. For better deliverability, send transactional mail from a separate LianaMailer account.

How contacts are handled

Each item in recipients needs an email or sms. Batch send also finds a contact by id alone, but not a contact that has only an SMS number. Any other keys are property values. They fill in the property placeholders in the draft, and are saved to the contact.

JSONRequest body
{ "letter": { "type": "draft", "id": 123 }, "recipients": [{ "email": "anna@example.com", "order_number": "10045" }], "tracking_id": "order10045" }

With this request, $order_number$ in the draft becomes 10045, and order_number is saved to the contact anna@example.com.

All three endpoints replace the contact's current values with the ones you send, and create any properties that do not exist yet. Send only values that should stay on the contact, and do not use the reserved property names.

Event send

Event send finds each contact by email or sms, and ignores list memberships. It ignores id when email is given, and a contact given by id alone makes the whole request fail with a valid email or sms is required. What happens to each contact:

ContactWhat happens
Not foundCreated, and confirmed unless your account requires double opt-in
Has left its listsGets the mail
Unconfirmed, with double opt-inDoes not get the mail
DeletedDoes not get the mail, and stays deleted
PseudonymizedFound by email address, and restored with its old ID
ForgottenSkipped, and not created again

The request fails if it has the same contact twice, or if none of its contacts can get the mail. If a contact has already received this draft's event mail, the request fails and no one gets the mail. To send the mail to a contact again, set letter.recipients_reset to true.

The contacts that event send creates are not on any mailing list, and an event delivery does not protect them from the daily cleanup, so they are deleted after a week. To keep them, add them to a list.

Batch and web page send

Batch send and web page send first import the contacts in recipients into a new hidden mailing list, named adhoc-delivery-draft- followed by the ID and revision of the draft copy. The import works like a list import with the default options.

New contacts are created and confirmed, and existing contacts are updated and get the mail, even if they have left your other lists. Deleted, bounced and forgotten contacts are skipped, and pseudonymized contacts are restored. Property values are saved as contact properties, not list-specific ones, and LianaAutomation events are recorded.

The contacts become regular contacts in your account, but the hidden list does not count as a membership. It does not appear in membership in the getRecipient response, and it does not protect the contacts from the daily cleanup.

The request returns only after the import is done, so a long recipients array makes it slow. For a large or recurring audience, import the contacts into a mailing list first, and send to the list.

After sending

The response has the delivery IDs in deliveries and the mail IDs in mails. Batch send and web page send also return the ID of the draft copy in id. Event send returns a tracking ID, which is your tracking_id or a generated one.

A mail is the copy of the content that a delivery sent, so a mail ID is not a draft ID. mails, mail_id in getDelivery and the v1 Mails endpoints use mail IDs. Do not pass a mail ID as letter.id.

To follow the progress, call getDeliveryStatuses. It returns the number of contacts and delivered messages of each delivery, and whether sending is done. getDelivery returns the details of one delivery.

getScheduledDeliveries lists the scheduled deliveries. To stop one before it is sent, call cancelDelivery, or cancelDeliveryRelated to cancel all the deliveries of a send to several lists or of an A/B test. There is no endpoint for changing the time, so cancel the delivery and send it again.

getDeliveryReport has the result counts of one delivery, and the v3 delivery reports list who opened it or clicked its links. The v3 events endpoint returns opens, clicks and bounces across deliveries, and a mailsent event for each contact that an event send mailed.

If a send fails with sending blocked, hasTemporaryBlock shows whether your account has a temporary block.

Retrying a batch send

Each batch or web page send request creates a new delivery, so sending the same request twice sends the mail twice. A request that fails with an A/B timeout error may still have created a delivery. Before you retry, check whether the delivery exists, for example with getDeliveriesRange or getScheduledDeliveries.

Limits

  • v1 and v2 allow at most four requests per second.
  • Event send can attach files in letter.attachments. This needs the attachments feature, and your account limits the size of each file and their total size.
  • letter.ab.wait_period must be at least 3600 seconds.
Last modified on