{"record":{"id":"c7d4b83210151197","repo":"quarkusio/quarkus","slug":"unable-to-send-an-email","errorCode":null,"errorMessage":"Unable to send an email","messagePattern":"Unable to send an email","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/mailer/runtime/src/main/java/io/quarkus/mailer/runtime/MutinyMailerImpl.java","lineNumber":247,"sourceCode":"\n    private void validate(List<String> to, List<String> cc, List<String> bcc) {\n        try {\n            for (String email : to) {\n                new EmailAddress(email);\n            }\n            for (String email : cc) {\n                new EmailAddress(email);\n            }\n            for (String email : bcc) {\n                new EmailAddress(email);\n            }\n        } catch (IllegalArgumentException e) {\n            // One of the email addresses is invalid\n            if (logInvalidRecipients) {\n                // We are allowed to log the invalid email address\n                // The exception message contains the invalid email address.\n                LOGGER.warn(\"Unable to send an email\", e);\n                throw new IllegalArgumentException(\"Unable to send an email\", e);\n            } else {\n                // Do not print the invalid email address.\n                LOGGER.warn(\"Unable to send an email, an email address is invalid\");\n                throw new IllegalArgumentException(\"Unable to send an email, an email address is invalid\");\n            }\n        }\n    }\n\n    private MultiMap toMultimap(Map<String, List<String>> headers) {\n        MultiMap mm = MultiMap.caseInsensitiveMultiMap();\n        headers.forEach(mm::add);\n        return mm;\n    }\n\n    private Uni<MailAttachment> toMailAttachment(Attachment attachment) {\n        MailAttachment attach = MailAttachment.create();\n        attach.setName(attachment.getName());\n        attach.setContentId(attachment.getContentId());","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/mailer/runtime/src/main/java/io/quarkus/mailer/runtime/MutinyMailerImpl.java#L229-L265","documentation":"MutinyMailerImpl.validate() catches IllegalArgumentException from address parsing when an email address is invalid. When logInvalidRecipients is enabled (quarkus.mailer.log-invalid-recipients=true), it logs and rethrows with the generic message \"Unable to send an email\", preserving the original exception (which contains the offending address) as the cause.","triggerScenarios":"Sending a mail whose to/cc/bcc/from/reply-to address fails address validation (e.g. \"not-an-email\", missing domain, unbalanced quotes) while log-invalid-recipients is true.","commonSituations":"User-supplied addresses with typos or stray whitespace/characters; addresses assembled by string concatenation (e.g. name <email> with malformed name part); test data with placeholder addresses like \"foo@bar\" missing TLD depending on parser strictness.","solutions":["Validate/normalize email addresses before building the Mail (regex or a validation library like Commons Validator / Hibernate Validator @Email).","Inspect the cause of the exception — it names the invalid address; fix that specific value.","If addresses come from user input, add form-level validation and reject invalid input early.","Trim whitespace and ensure the \"Name <addr>\" syntax is correct for display-name addresses."],"exampleFix":"// before\nString to = request.getEmail(); // unchecked\nmailer.send(Mail.withText(to, subject, body));\n\n// after\nString to = request.getEmail().trim();\nif (to.matches(\"^[^@\\\\s]+@[^@\\\\s]+\\\\.[^@\\\\s]+$\")) {\n    mailer.send(Mail.withText(to, subject, body));\n} else {\n    throw new WebApplicationException(\"Invalid recipient\", 400);\n}","handlingStrategy":"validation","validationCode":"private static final Pattern EMAIL = Pattern.compile(\"^[^@\\\\s]+@[^@\\\\s]+\\\\.[^@\\\\s]+$\");\nif (!EMAIL.matcher(recipient.trim()).matches()) {\n    throw new IllegalArgumentException(\"Invalid recipient: \" + recipient);\n}","typeGuard":"static boolean isValidEmail(String address) {\n    return address != null && !address.isBlank() && EMAIL.matcher(address.trim()).matches();\n}","tryCatchPattern":"try {\n    mailer.send(mail).await().indefinitely();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Unable to send an email\")) {\n        LOG.errorf(e, \"Email address rejected; cause names the invalid address\");\n    }\n    throw e;\n}","preventionTips":["Validate all recipient fields (to/cc/bcc/from/reply-to) before building Mail","Trim and normalize user-supplied addresses at the boundary","Use bean validation (@Email) on DTOs carrying addresses","Enable log-invalid-recipients in dev/test to see offending values"],"tags":["quarkus","mailer","email-validation","invalid-address","illegal-argument"],"backgroundTag":"invalid-email-address","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}