flowable/flowable-engine · error · FlowableMailException

Could not set as from address in email

Error message

Could not set  as from address in email

What it means

setFrom applies the From address to the MimeMessage; if message.setFrom throws MessagingException after the address was constructed, the client wraps it in FlowableMailException naming the address: 'Could not set <address> as from address in email'. Note that a syntactically invalid From address would usually fail earlier with 'Invalid email' in createInternetAddress.

Source

Thrown at modules/flowable-mail/src/main/java/org/flowable/mail/common/impl/jakarta/mail/JakartaMailFlowableMailClient.java:238

        // localPart@domainPart
        return email.substring(0, atIndex) + '@' + IDN.toASCII(email.substring(atIndex + 1));

    }

    protected void setFrom(MimeMessage message, String from) {
        String fromAddress;

        if (from != null) {
            fromAddress = from;
        } else { // use default configured from address in defaults configuration
            fromAddress = defaultsConfiguration.defaultFrom();
        }

        try {
            message.setFrom(createInternetAddress(fromAddress));
        } catch (MessagingException e) {
            throw new FlowableMailException("Could not set " + fromAddress + " as from address in email", e);
        }
    }

    protected void setSentDate(MimeMessage message) {
        try {
            if (message.getSentDate() == null) {
                message.setSentDate(new Date());
            }
        } catch (MessagingException e) {
            throw new FlowableMailException("Failed to set send date", e);
        }
    }

    protected void setContent(MimeMessage mimeMessage, MailMessage message, String charset) {
        String text = message.getPlainContent();
        String html = message.getHtmlContent();
        Collection<DataSource> attachments = message.getAttachments();
        boolean attachmentsExists = attachments != null && !attachments.isEmpty();

View on GitHub (pinned to d6d39ce1c6)

Solutions

  1. Check the wrapped MessagingException cause for the exact reason and correct the from address in the request or in the defaults configuration.
  2. Verify the configured defaultFrom is a valid, permitted sender for your mail server (SPF/relay rules).
  3. Explicitly set a known-good from address on the SendMailRequest instead of relying on defaults.
  4. Confirm the JNDI/host-based mail session is configured for the domain you send from.

Example fix

// before
cfg.setDefaultFrom("""do-not-reply"""); // not an address

// after
cfg.setDefaultFrom("do-not-reply@example.com");
Defensive patterns

Strategy: validation

Validate before calling

boolean isValidEmail(String s) {
    if (s == null) return false;
    try { new jakarta.mail.internet.InternetAddress(s.trim(), true).validate(); return true; }
    catch (jakarta.mail.internet.AddressException e) { return false; }
}
// assert isValidEmail(cfg.getDefaultFrom()) at startup

Try / catch

try { client.sendMail(request); } catch (FlowableMailException e) { if (e.getMessage().contains("as from address")) { log.error("bad from address: " + e.getMessage(), e.getCause()); } throw e; }

Prevention

When it happens

Trigger: Executing a send where the resolved From address (explicit request.from or the configured defaultFrom) causes MimeMessage.setFrom to throw — e.g. address already set illegally, or header issues during setFrom.

Common situations: Misconfigured default from address in mail server configuration; from address overridden per request with values from external systems; mail session/provider rejecting the identity configured.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11). Data as JSON: /api/errors/4a72039943b14d14. Report an issue: GitHub.