← Back to blog

Spring @Scheduled Transactional Email with Rovela (2026): Cron + Idempotency-Key per Window

Wire Spring @Scheduled cron methods to Rovela POST /emails with server-only sending_access and a window-scoped Idempotency-Key for digests and ops reports.

Updated November 9, 2026
Spring @Scheduled Transactional Email with Rovela (2026): Cron + Idempotency-Key per Window

Spring @Scheduled owns the schedule — Rovela delivers the mail

Spring’s @Scheduled annotation (with @EnableScheduling) runs cron, fixedRate, and fixedDelay methods on Spring beans via a TaskScheduler. Cron strings are typically six-field (second minute hour day month weekday). That fits digests whose HTML depends on live JPA/state at fire time rather than a body frozen earlier with Rovela scheduled_at.

Distinct from Quartz Scheduler Transactional Email (full JobDetail/Trigger APIs) and from Spring Boot OTP Email API (one-shot verification) — this post is annotation @Scheduled recurring mail only.

Rovela queues, DKIM-signs, and delivers when your job method calls POST https://api.rovela.dev/emails (Send Email API, Quick Start, Authentication). Spring @Scheduled owns the cadence and “is due?” logic. Your job method owns aggregation, secrets for sending_access, and a stable Idempotency-Key per schedule window. Rovela only delivers.

This guide wires Spring @Scheduled → job method → Rovela that:

  1. Declares @Scheduled(cron = "0 0 9 * * *", zone = "UTC") on a Spring bean method (optionally with a shedlock / single-instance guard)
  2. Keeps ROVELA_API_KEY (sending_access), MAIL_FROM, and recipients in server-only config — never in browsers, SPA bundles, or a public Git tree
  3. Aggregates a digest / report for the current schedule window inside the job method
  4. Sends via Rovela with a window-scoped Idempotency-Key
  5. Survives retries, restarts, and multi-worker fleets without duplicate mail

Rovela does not create Spring @Scheduled schedules, workers, or storage. Spring @Scheduled owns schedule → enqueue/fire → execute. Your job method owns query → map fields → POST /emails. Rovela owns delivery.

Distinct from:

Also distinct from one-off @Async mail sends — this post is the recurring cron path.

What Spring @Scheduled schedules vs what Rovela sends

ConcernOwner
Cron / fixedRate / zoneSpring @Scheduled
TaskScheduler thread poolSpring scheduling config
App process must stay upSpring Boot host
Server secrets for ROVELA_API_KEY (sending_access)Process / worker env / secret store
Query DB / APIs for the windowYour job method
Render HTML + textYour job method
POST /emails, DKIM, queue, bouncesRovela
Idempotency-Key = spring-scheduled-daily-digest:{yyyy-mm-dd}Your job method

A 200 from Rovela means accepted and queued, not “already in the inbox” (Quick Start).

Spring @Scheduled constraints that shape the email job

  • The Spring Boot process must stay up.

  • Every replica runs @Scheduled by default — use ShedLock / leader election / a dedicated worker profile for mail crons.

  • Six-field cron (seconds first) — not Unix five-field.

  • Set zone explicitly on @Scheduled.

  • Prefer Quartz integration when you need clustering, misfire policies, and JobDetail persistence out of the box.

  • Keep sending_access server-only. Store ROVELA_API_KEY in environment / vault — never in client apps or public Git (Authentication).

  • Prefer HTTPS POST /emails. Outbound SMTP from a worker is a poor fit (Email API vs SMTP).

When to use Spring @Scheduled + POST /emails (not scheduled_at)

Use Spring @Scheduled → live send when:

  • The HTML must include fresh metrics at fire time
  • You already run Spring @Scheduled and want schedules next to the same workers
  • You need cron-like digests without adopting a separate SaaS scheduler
  • One (or a few) transactional messages go to ops / founder / customer addresses looked up at run time

Use Rovela scheduled_at when the body is already correct and you only need “deliver later” without a running scheduler (Scheduled Email Sending). Prefer Quartz when schedules must survive multi-node clustering with JDBCJobStore; prefer @Scheduled for simple single-worker annotation cron.

Prerequisites

  1. A verified sending domain in Rovela. Unverified from domains are refused with 400 (Quick Start).
  2. An API key shaped like re_…. Prefer sending_access for the worker (Authentication).
  3. Spring Boot app with @EnableScheduling and a long-lived process.
  4. Config: ROVELA_API_KEY, MAIL_FROM, DIGEST_TO.
  5. RestClient / WebClient / HttpClient bean for Rovela calls.

Register the schedule

@SpringBootApplication
@EnableScheduling
public class Application {
  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }
}
@Component
public class DigestScheduler {
  private final DigestMailer mailer;
  public DigestScheduler(DigestMailer mailer) { this.mailer = mailer; }

  @Scheduled(cron = "0 0 9 * * *", zone = "UTC")
  public void dailyDigest() {
    mailer.sendDailyDigest();
  }

  @Scheduled(cron = "0 */15 * * * *", zone = "UTC")
  public void opsPulse() {
    mailer.sendOpsPulse();
  }
}

Job method that calls Rovela

@Service
public class DigestMailer {
  private final RestClient http;
  private final Environment env;

  public DigestMailer(RestClient.Builder builder, Environment env) {
    this.http = builder.baseUrl("https://api.rovela.dev").build();
    this.env = env;
  }

  public void sendDailyDigest() {
    String day = java.time.LocalDate.now(java.time.ZoneOffset.UTC).toString();
    String idempotencyKey = "spring-scheduled-daily-digest:" + day;
    // aggregate stats from repositories...
    String apiKey = env.getRequiredProperty("ROVELA_API_KEY");
    String from = env.getRequiredProperty("MAIL_FROM");
    String[] to = env.getRequiredProperty("DIGEST_TO").split(",");

    // never log apiKey
    Map<String, Object> body = Map.of(
      "from", from,
      "to", to,
      "subject", "Acme daily digest — " + day,
      "html", "<h1>Daily digest — " + day + "</h1>",
      "text", "Daily digest — " + day,
      "tags", Map.of("kind", "spring-scheduled-daily-digest", "day", day, "platform", "spring-scheduled")
    );

    try {
      Map<?,?> res = http.post()
          .uri("/emails")
          .header("Authorization", "Bearer " + apiKey)
          .header("Idempotency-Key", idempotencyKey)
          .contentType(MediaType.APPLICATION_JSON)
          .body(body)
          .retrieve()
          .body(Map.class);
      // log res.get("id")
    } catch (Exception e) {
      throw new IllegalStateException("Rovela send failed", e);
    }
  }
}

Window-scoped Idempotency-Key

Rovela’s Idempotency-Key (up to 256 characters) makes a retry of the same send within 24 hours return the original response instead of mailing again (Send Email API). That matters because:

  • Retries re-enter the job after 5xx / timeouts
  • Crash after Rovela 200 but before the job is marked succeeded can redeliver
  • Queue lag can shift wall-clock — key off the business schedule window, not millisecond now
  • Multi-tenant jobs need tenant ids in the key

Recommended keys:

KeyUse when
spring-scheduled-daily-digest:{yyyy-mm-dd}One ops digest per UTC day
spring-scheduled-ops-pulse:{yyyy-mm-dd}T{HH}-{MM}/15 or hourly crontab (bucket to the window)
spring-scheduled-tokyo-ops:{yyyy-mm-dd}Local-TZ morning digest
spring-scheduled-weekly-report:{yyyy}-W{ww}One founder report per ISO week
spring-scheduled-tenant-digest:{tenantId}:{yyyy-mm-dd}Per-tenant job args

If you mail many personalized digests in one job, prefer per-recipient keys (or POST /emails/batch for up to 100 non-template messages — batch rejects template / topic_id by design).

Attach secrets and verify the schedule

  1. Set ROVELA_API_KEY (sending_access), MAIL_FROM, DIGEST_TO on the process that runs the scheduler/worker.
  2. Confirm the schedule entry is registered with the expected cron and timezone.
  3. Confirm workers are online.
  4. Wait for the next tick, or trigger once in non-prod while keeping the window key stable.
  5. Check logs for idempotencyKey + Rovela emailId. Optionally correlate later with Rovela webhooks.

Prefer sending_access on production senders — never full_access. Never log API keys. Rotate Rovela by create-then-revoke.

Failure modes and how to handle them

SymptomLikely causeWhat to do
Cron never firesScheduler/worker downKeep the scheduling process always on
Double digestsMultiple schedulers / replicasSingle leader or distributed lock / persistent store
Wrong wall timeAssumed UTC / wrong timezoneSet timezone explicitly
Duplicate digests after retriesUnstable key / keyed by ms nowUse window-scoped keys; Idempotency-Key collapses duplicates within 24h
Rovela 401Bad / missing ROVELA_API_KEYFix server env; confirm sending_access
Rovela 400 naming a domainMAIL_FROM domain not verifiedVerify the domain under Rovela Domains
Rovela 429Rate limitRaise/retry; keep the same Idempotency-Key
Secrets in GitKey committedKeep only in env / vault

Production checklist

  • Verified Rovela sending domain; MAIL_FROM matches it
  • ROVELA_API_KEY is sending_access, in worker env / vault only
  • Scheduler + workers always running as documented for Spring @Scheduled
  • Documented cron + timezone
  • Rovela send uses a window-scoped Idempotency-Key
  • Logs show successful emailId without printing secrets
  • Alerts on consecutive job failures / scheduler down
  • Optional: Rovela webhooks for email.bounced / email.complained on digest recipients

FAQ

Can the scheduler call Rovela without a job method? No usefully — the scheduler only wakes your code. Your method must aggregate live data and keep sending_access local. Rovela does not host your scheduler or workers.

Should I use Rovela scheduled_at from the job? Usually no. If the scheduler already fires at send time with a live body, call POST /emails immediately. Use scheduled_at when you accept the message now and want Rovela to deliver later without another wake (Scheduled Email Sending).

What key scope does sending_access cover? Enough to queue mail via POST /emails / batch. Reading messages, rescheduling, and cancel need full_access or a dashboard session (Send Email API, Authentication). Keep the worker on sending_access.

Does a 200 mean the founder already got the digest? No — it means Rovela accepted and queued the message. Use GET /emails/:id, events, or webhooks for delivery state (Quick Start).

Why both scheduler retries and Rovela Idempotency-Key? The scheduler retries the job when your code fails. Rovela’s key collapses duplicate sends if the HTTP call succeeds twice in the same window (or times out after Rovela accepted). You want both layers.

Ship the recurring job; let Rovela deliver

Register the Spring @Scheduled schedule with an explicit cron and timezone, put live aggregation and POST /emails in the job method, scope Idempotency-Key to the schedule window (and tenant), and keep sending_access server-only. Spring @Scheduled wakes on time; Rovela delivers the transactional mail.