← Back to blog

Play Framework Transactional Email API (2026): Notify That a Data Import Finished and the Report Is Ready with POST /emails

Send a “a data import finished and the import report is ready — here is the import permalink the operator already has” notice from a Play Framework job or scheduled task with Rovela’s HTTP API: a Bearer key from the process environment, WSClient or Java HttpClient to POST /emails, and an Idempotency-Key. No official Play plugin. Distinct from Appwrite function-execution-error, backup-failed, Sanic vulnerability-scan-finished, Chi background-job-failed, and this batch’s export-failed guide.

Updated November 11, 2026
Play Framework Transactional Email API (2026): Notify That a Data Import Finished and the Report Is Ready with POST /emails

An import-finished notice is not a backup-failed, function-error, or export-failed mail

When a data import has already finished in your Play Framework app — a nightly catalog load, a partner inventory file, a customer-list upload the operator already kicked off — that job or scheduled task still has to tell the data operator: “The import finished and the report is ready,” plus the import-job permalink you already have. That send is transactional email. It is not a newsletter, not a marketing drip, and it is not a rewrite of the Appwrite function-execution-error, backup failed, Sanic vulnerability-scan-finished, Chi background-job-failed, Axum webhook-delivery-failed, incident resolved, or ticket reply guides. Those tutorials already exist, and they describe failed jobs, scans, or support events. This article is one event in your own Play import workflow: the inbound import already completed successfully, and the import report is already ready. It is also distinct from this batch’s export failed guide, which is a user’s outbound export that did not finish. The recipient is the data operator / admin (the address you already store on that import job). The call to action is “open this import report,” not “a backup job failed,” not “a function execution ended with an error,” and not “an export of existing data failed.”

It is also not a generic “send email from Play” rewrite of the Spring Boot or Quarkus guides. Those cover other JVM stacks and other notification stories. There is no official Play plugin and no client library to install. Use Play’s WSClient (or Java’s HttpClient) plus curl when you want to prove the JSON. The JSON body and headers are the product. The Play job or scheduled task that already marked the import finished should send the notice; Rovela does not run the import and does not parse the report.

Rovela’s Email API is a single HTTPS call. The base URL is https://api.rovela.dev. You authenticate with Authorization: Bearer re_… (Authentication) and queue a message with POST /emails. The response is {"object":"email","id":"..."}. HTTP 200 means the message was accepted and queued, not that it has already arrived (Quick Start).

If you are still choosing between HTTP and SMTP, read Email API vs SMTP. Rovela’s SMTP is mailbox SMTP for mail apps (mx.rovela.dev:465, a device credential, send-as-self, 30 messages a minute from one client address). Programmatic volume from a Play job or scheduled task belongs on POST /emails, which is also the distinction drawn in Email API vs SMTP relay.

A Play Framework job or scheduled task records that a data import finished and the report is ready, then WSClient posts JSON with the import permalink to the email API and receives a message id

What you need before the first import-finished notice

The first-email guide and the Quick Start are the same five steps, whether the caller is curl or WSClient inside a Play job:

  1. Create an account. You start on the free plan, which sends real mail. There is no separate sandbox, and no test key that behaves differently from production.
  2. Add and verify a sending domain (a subdomain such as mail.example.com is a common choice). You cannot send from a domain you have not verified; an unverified or foreign from is refused with a 400 that names the domain. The dashboard asks for four DNS records — SPF, DKIM, DMARC, and return-path. See the domain setup guide, the Domains API, and what domain email is.
  3. Create an API key. A sending_access key can send and nothing else — the right default for a production import notifier. A full_access key can also read messages and events, and manage domains, templates, and webhooks. The full key is shown once.
  4. Send with POST /emails.
  5. Confirm delivery in the dashboard, with GET /emails/:id or GET /emails/:id/events (those reads need full_access or a dashboard session), or with a webhook.

from is a string in the documented form "Imports <imports@yourdomain.com>". The address must sit on a verified sending domain. That is the same rule that makes domain email trustworthy: you prove you control the domain before you speak as it. How the display name and the address work is covered in the From name guide and the sending domains API overview.

At least one of html, text, or template is required. Send both html and text where you can — many clients preview the text part, which is often where the operator first sees the import-job permalink (HTML email API).

A Play job that sends after the import is already finished

Keep the Rovela key out of the browser, out of a public repository, and out of a container image. A leaked sending_access key can send mail as your domain. The Play job or scheduled task that already marked the import finished and the report ready should read ROVELA_API_KEY from its process environment and call Rovela only on the server (email API authentication). If an operator starts the import from a controller, write your own import-job record first (status finished, report permalink already minted), then enqueue the notice. Do not call the Email API from a browser request, and do not invent a Rovela Play plugin — none exists.

Store the event first: the import-job id you already have, a short job name you already show on the report page, the operator’s address, and the import-job permalink. The send is just the notice. The recipient is consistently the data operator or admin who owns that import — not every analyst in the workspace, not a marketing segment, and not the partner who uploaded the file unless that is the address you already store. If a shared operations inbox also needs a copy, add that address deliberately. Key the Idempotency-Key to that finished-import event so a retried job does not mail the same “the report is ready” notice twice. A later import by the same operator is a different event and should be a different key. If a user’s outbound export later fails, that is this batch’s export-failed guide, not this one.

// app/services/RovelaClient.scala
// Play Framework job helper. WSClient. No official Rovela Play plugin.
package services

import play.api.libs.json._
import play.api.libs.ws.WSClient

import scala.concurrent.{ExecutionContext, Future}

class RovelaClient(ws: WSClient)(implicit ec: ExecutionContext) {
  private val Api = "https://api.rovela.dev"

  private def env(name: String): String =
    sys.env.getOrElse(name, throw new RuntimeException(s"missing $name"))

  def sendEmail(
      to: String,
      subject: String,
      html: String,
      text: String,
      idempotencyKey: String,
      replyTo: Option[String],
      tags: JsObject
  ): Future[String] = {
    val base = Json.obj(
      "from" -> env("ROVELA_FROM"),
      "to" -> to,
      "subject" -> subject,
      "html" -> html,
      "text" -> text,
      "tags" -> tags
    )
    val body = replyTo.fold(base)(value => base + ("reply_to" -> JsString(value)))

    ws.url(s"$Api/emails")
      .addHttpHeaders(
        "Authorization" -> s"Bearer ${env("ROVELA_API_KEY")}",
        "Content-Type" -> "application/json",
        "Idempotency-Key" -> idempotencyKey
      )
      .post(body)
      .map { res =>
        val payload = res.json
        if (res.status >= 400) {
          val message = (payload \ "message").asOpt[String].getOrElse(s"rovela ${res.status}")
          throw new RuntimeException(message)
        }
        (payload \ "id").asOpt[String].getOrElse("")
      }
  }

  def notifyImportFinished(
      operatorEmail: String,
      jobName: String,
      importPermalink: String,
      importJobId: String
  ): Future[String] = {
    val subject = s"Your data import finished and the report is ready: $jobName"
    val text =
      s"The data import $jobName finished, and the import report is ready.\n\nOpen the import report: $importPermalink"
    val html =
      s"<p>The data import ${escape(jobName)} finished, and the import report is ready.</p>" +
        s"""<p><a href="${escape(importPermalink)}">Open the import report</a></p>"""
    sendEmail(
      operatorEmail,
      subject,
      html,
      text,
      s"import-finished-$importJobId",
      sys.env.get("ROVELA_REPLY_TO"),
      Json.obj("type" -> "import_finished")
    )
  }

  private def escape(value: String): String =
    value.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace("\"", "&quot;")
}

If your Play app is Java rather than Scala, the same JSON can be posted with java.net.http.HttpClient:

HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.rovela.dev/emails"))
    .header("Authorization", "Bearer " + apiKey)
    .header("Content-Type", "application/json")
    .header("Idempotency-Key", idempotencyKey)
    .POST(HttpRequest.BodyPublishers.ofString(jsonBody))
    .build();
HttpResponse<String> response = HttpClient.newHttpClient()
    .send(request, HttpResponse.BodyHandlers.ofString());

Call notifyImportFinished from a Play job or a scheduled task that already wrote the finished row — after the permalink exists, not before. A typical pattern is an Akka or Play scheduled job that finalizes the import, writes the report, then sends the notice, or a consumer that drains your own import_finished queue. Keep the HTTP call out of the request path that merely uploads the file; the operator should be mailed when the import has actually finished and the report is ready, not when they first click “start import.” The email is a status notice, not a place to paste every rejected row. If a later pass marks the same import as superseded, that is a different event and should use a different idempotency key — do not reuse the import-finished key.

The same JSON can be sent with curl, which is useful in a staging shell while you confirm the verified from and the permalink:

curl -X POST https://api.rovela.dev/emails \
  -H "Authorization: Bearer $ROVELA_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: import-finished-imp_01H8Q2" \
  -d '{
    "from": "Imports <imports@yourdomain.com>",
    "to": "operator@example.com",
    "subject": "Your data import finished and the report is ready: Nightly catalog load",
    "html": "<p>The data import Nightly catalog load finished, and the import report is ready.</p><p><a href=\"https://app.example.com/imports/imp_01H8Q2\">Open the import report</a></p>",
    "text": "The data import Nightly catalog load finished, and the import report is ready.\n\nOpen the import report: https://app.example.com/imports/imp_01H8Q2",
    "reply_to": "imports@yourdomain.com",
    "tags": {"type": "import_finished"}
  }'

reply_to is documented and optional; use it when replies should reach an operations inbox rather than the sending address (reply-to). tags may be an object or an array of arbitrary labels — they are yours to choose, and they help you filter later in the dashboard or in webhooks (email API tags). headers and topic_id are also documented fields; this tutorial does not treat topic_id as a product tour. Attachments, if you ever add a short import-summary CSV, use { filename, content (base64), content_type }. Do not attach the raw partner file, credentials, or a full dump of rejected rows. The permalink is the call to action (email attachments).

If you ever need to notify many independently finished imports in one go (a morning catch-up, not the usual single-job path), POST /emails/batch accepts up to 100 messages, each with the same schema. Two fields are rejected rather than ignored: template and topic_id. Send those through POST /emails. See the batch example and the batch transactional email guide. Each item should still carry its own business key if you send them as individual POST /emails calls; if you use the batch endpoint, keep the rest of the payload identical to a single send, without template or topic_id.

template is documented as { id, variables } and is mutually exclusive with html and text. This tutorial sends both html and text so the operator can open the import permalink even in a text-only client. If you later switch a stable notice to a stored template, drop html and text and follow the Templates API, the templates guide, and the email templates API guide.

Idempotency, recipients, and what a 200 actually means

Play jobs and scheduled tasks retry, and a “the import report is ready, notify the operator” path can run more than once for the same record. Send an Idempotency-Key header (up to 256 characters). A retry of the same request within 24 hours returns the original response instead of sending again (idempotency). Key it to the import-job id (or to a specific finished-import event id you already store), not to the clock and not to the operator’s email alone. If the same person later has a different import finish, that is a second notice and a second key.

A message may address at most 50 recipients across to, cc, and bcc combined. That is the transport’s limit, not a plan limit, and it is checked before the request is accepted. Quota is charged per recipient, not per message — cc and bcc count the same as to. An import-finished notice addresses the data operator who owns that job. If a shared operations mailbox also has to be told, add that address deliberately and accept that it counts as a second recipient. Do not cc every analyst by default.

HTTP 200 from POST /emails means the message was accepted and queued. It is not a delivery receipt. The JSON is {"object":"email","id":"..."}. Persist that id next to the import job if you want to look the message up later from a dashboard session. Do not block the Play job until a mailbox provider confirms delivery.

scheduled_at is a documented ISO 8601 future timestamp if you ever need to hold a notice. For an import that is already finished and whose report is ready, send immediately after the finished record is written. If you did schedule a message and the operator should not receive it, POST /emails/:id/cancel cancels an unsent message. Reading, cancelling, and any rescheduling need full_access or a dashboard session. This article does not invent a reschedule request body.

Errors you should handle in the Play job

Documented send errors use an envelope of { statusCode, name, message }:

  • 400 — a missing required field, a from domain that does not belong to your organization, a template that does not exist, or more than 50 recipients on one message. Fix the payload; retrying the same body will fail the same way.
  • 401 — a missing, malformed, or revoked Bearer key. Check the process environment, not the import-job row.
  • 429 — you are being rate limited. Back off and retry with the same Idempotency-Key so a later attempt cannot send a second notice for the same import (rate limits, retries).

Treat unknown 5xx responses as retryable with the same key. Log name and message next to the import-job id; do not log the Bearer key. A practical walk-through is the email API error handling guide.

Delivery is asynchronous — do not poll from the job

A 200 from POST /emails means accepted for delivery, not delivered. Reading GET /emails/:id or GET /emails/:id/events needs a full_access key or a dashboard session; a sending_access key cannot do it, and you should not add a polling loop inside the Play job. Subscribe to a webhook instead, and verify the signature header x-resend-signature as documented in webhook security and signature verification. Event names include accepted, delivered, opened, clicked, bounced, or failed. For a single message you can also use the email delivery status API or the dashboard from a support session.

A generic backup-failed or function-error notice is a different tutorial; a Play job posts an import-finished notice with the import permalink using POST /emails

What not to do in this import-finished notice

  • Do not put the Rovela key in a browser client, a public repository, or a container image.
  • Do not invent an official Play plugin or a Rovela import product. Your job already recorded that the import finished and the report is ready; Rovela delivers the mail. There is no official client library.
  • Do not send this as a “backup failed,” “function execution error,” “vulnerability scan finished,” or “export failed” template borrowed from another tutorial. The permalink is an import report, and the recipient is the data operator.
  • Do not include partner credentials, raw source files, or a dump of every rejected row in the email body. The notice carries a short job name and the permalink.
  • Do not send from mailbox SMTP for this. SMTP is for mail apps and mailboxes. A Play job should use the HTTP API. Inbound mail into a hosted mailbox is a different path, described in the webmail manual; this guide is an outbound import-finished notice.
  • Do not poll GET /emails/:id with a sending_access key, and do not invent a reschedule body if you later cancel an unsent message.

A compact import-finished checklist

  1. Verify the sending domain and create a sending_access key (Quick Start).
  2. Put ROVELA_API_KEY and ROVELA_FROM in the Play job or scheduled task’s process environment, not in the browser.
  3. Record the finished import first: operator address, job name, and the import-job permalink.
  4. Call POST /emails with WSClient (or Java HttpClient), both html and text, a reply_to if you want replies in an operations inbox, and an Idempotency-Key scoped to that import-job id.
  5. Treat HTTP 200 as accepted, not delivered. Persist the returned message id if you need it later.
  6. Confirm delivery with a signed webhook or from the dashboard.
  7. If you are comparing providers, the existing pages are Rovela vs Mailgun, vs Amazon SES, vs Postmark, vs SendGrid, vs Resend, and vs Brevo. For the HTTP shape itself, see the transactional email API, the curl sending guide, and the HTTP email API overview. For other notification patterns, see the email notification API guide.