{"record":{"id":"e964b0b68116d68a","repo":"flowable/flowable-engine","slug":"could-not-add-as-recipient","errorCode":null,"errorMessage":"Could not add  as  recipient","messagePattern":"Could not add  as  recipient","errorType":"exception","errorClass":"FlowableMailException","httpStatus":null,"severity":"error","filePath":"modules/flowable-mail/src/main/java/org/flowable/mail/common/impl/jakarta/mail/JakartaMailFlowableMailClient.java","lineNumber":199,"sourceCode":"    protected void addBcc(MimeMessage message, Collection<String> bcc) {\n        addRecipient(message, bcc, Message.RecipientType.BCC);\n    }\n\n    protected void addRecipient(MimeMessage message, Collection<String> recipients, Message.RecipientType recipientType) {\n        if (recipients == null || recipients.isEmpty()) {\n            return;\n        }\n        Collection<String> newRecipients = recipients;\n        Collection<String> forceRecipients = defaultsConfiguration.forceTo();\n        if (forceRecipients != null && !forceRecipients.isEmpty()) {\n            newRecipients = forceRecipients;\n        }\n        if (!newRecipients.isEmpty()) {\n            for (String t : newRecipients) {\n                try {\n                    message.addRecipient(recipientType, createInternetAddress(t));\n                } catch (MessagingException e) {\n                    throw new FlowableMailException(\"Could not add \" + t + \" as \" + recipientType + \" recipient\", e);\n                }\n            }\n        }\n    }\n\n    protected InternetAddress createInternetAddress(String email) {\n        try {\n            InternetAddress address = new InternetAddress(toASCIIEmail(email));\n            address.validate();\n            return address;\n        } catch (AddressException e) {\n            throw new FlowableMailException(\"Invalid email\", e);\n        }\n    }\n\n    protected String toASCIIEmail(String email) {\n        int atIndex = email.indexOf('@');\n        if (atIndex < 0) {","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-mail/src/main/java/org/flowable/mail/common/impl/jakarta/mail/JakartaMailFlowableMailClient.java#L181-L217","documentation":"addRecipient adds each recipient (To/Cc/Bcc) to the MimeMessage; if message.addRecipient throws MessagingException for a specific address, the client wraps it in FlowableMailException naming the offending address and recipient type. The message text is 'Could not add <address> as <TYPE> recipient'.","triggerScenarios":"Calling addTo/addCc/addBcc with an address string for which createInternetAddress succeeds parsing but Message.addRecipient fails, or an underlying addRecipient MessagingException during message assembly.","commonSituations":"Recipient lists loaded from external systems containing malformed or duplicate entries; addresses with illegal characters that pass initial parsing but fail at add time; group/distribution addresses the mail provider rejects.","solutions":["Read the exception message: it names the exact address that failed; remove or fix that entry in the recipient list.","Validate every address (regex or InternetAddress.validate()) before adding recipients.","Split batch sends so one bad recipient does not abort the whole email; handle per-recipient failures.","Check for whitespace/newlines embedded in addresses coming from user data or databases."],"exampleFix":"// before\nmailClient.addTo(SendMailRequest.builder(), List.of(\"a@x.com\", \"b at y.com\"));\n\n// after\nList<String> valid = recipients.stream()\n    .filter(r -> r != null && r.matches(\"^[^@\\\\s]+@[^@\\\\s]+\\\\.[^@\\\\s]+$\"))\n    .collect(Collectors.toList());\nmailClient.addTo(SendMailRequest.builder(), valid);","handlingStrategy":"validation","validationCode":"private static final Pattern EMAIL = Pattern.compile(\"^[^@\\\\s]+@[^@\\\\s]+\\\\.[^@\\\\s]+$\");\nList<String> validRecipients = recipients.stream().filter(r -> r != null && EMAIL.matcher(r.trim()).matches()).toList();","typeGuard":"boolean isValidRecipient(String a) { return a != null && EMAIL.matcher(a.trim()).matches(); }","tryCatchPattern":"try { builder.addTo(req, recipients); } catch (FlowableMailException e) { log.error(\"bad recipient: \" + e.getMessage(), e.getCause()); throw e; }","preventionTips":["Clean recipient lists before sending; drop duplicates and blanks.","Trim whitespace and newlines from addresses sourced from databases/CSV.","Send per-recipient where one invalid address must not block the batch."],"tags":["mail","recipients","jakarta-mail","email-validation"],"backgroundTag":"invalid-argument-format","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}