Error on amazon SES SendEmail operation Illegal addres
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Amazon SES rejects a SendEmail request with an "Illegal address" error when one of the email fields is malformed before delivery even starts. The failure usually has nothing to do with quotas or message content; it is almost always caused by a bad From, To, Cc, Bcc, or Reply-To value in the API request.
What SES Is Validating
SES expects each address to be a syntactically valid email address. In the simple SendEmail API, the fields are submitted as structured values, not as raw MIME headers, so the safest pattern is to send plain mailbox addresses such as [email protected].
Typical causes include:
- leading or trailing whitespace
- commas, semicolons, or accidental newline characters
- display-name formatting passed where only an address is expected
- empty strings inside a recipient list
- template data producing
None,null, or partial addresses
For example, this looks harmless but is a common source of failure:
The blank string and padded whitespace can easily become an SES validation error.
A Safe Way to Prepare Addresses
Before sending, normalize and validate every address that your application generates. Python's standard library can help with basic parsing, and you can reject obviously invalid values before calling AWS.
This does not implement a full RFC parser, but it catches the majority of application-level mistakes that lead to SES failures.
Sending with boto3
Once your addresses are normalized, keep the SES request simple. Avoid inserting display-name formatting unless you are intentionally building a raw MIME email through a different SES API.
If this fails with an illegal address message, log the exact addresses being submitted after normalization. That is usually faster than inspecting higher-level template code.
Distinguishing Address Errors from Other SES Problems
SES has several failure modes that people often mix together. A sandbox restriction, an unverified identity, or a region mismatch may prevent delivery, but those issues produce different errors. "Illegal address" is specifically about address parsing or invalid field contents.
That distinction matters during debugging. If the exception says illegal address, do not start by checking DKIM or IAM permissions. Start by printing the exact Source, ToAddresses, CcAddresses, BccAddresses, and ReplyToAddresses values that the SDK is sending.
In JavaScript, a small cleanup layer before the AWS SDK call is equally useful:
Even simple trimming prevents a surprising number of failures in form-driven applications.
Common Pitfalls
One frequent mistake is passing a comma-separated string where the SDK expects an array. Some developers build [email protected],[email protected] and send it as one item. SES then treats that entire string as a single invalid address.
Another issue is mixing display names with the simple API. A value like "Alice Example" <[email protected]> may parse in some contexts, but if your code is inconsistent across fields, the safest solution is to normalize to the mailbox address only.
Template expansion can also create broken addresses silently. If customer.email is missing, your code may generate an empty value and still include it in the destination list. Validate after template rendering, not before.
Finally, avoid logging only the raw exception. If you do not capture the cleaned request values, you can spend a long time inspecting unrelated email logic while the real problem is a single malformed string.
Summary
- SES "Illegal address" errors are usually caused by malformed
Fromor recipient values. - Normalize and validate addresses before calling
SendEmail. - Send plain mailbox addresses in the simple API unless you intentionally need raw MIME behavior.
- Log the final values submitted to SES so you can find empty strings, whitespace, or malformed entries quickly.
- Do not confuse address validation failures with identity verification, sandbox, or permission problems.
Related reading
- error on creating spring Embedded kafka instance
- error one of src or dest must be a remote file specification
- error OpenCV4.1.0 error -215Assertion failed ssize.empty in function 'cvresize
- ERROR org.apache.kafka.common.utils.KafkaThread - Uncaught exception in thread 'kafka-producer-network-thread
- Error org.springframework.kafka.KafkaException Seek to current after exception;
- error package org.apache.kafka.clients.producer does not
- Error parsing parameter '--expression-attribute-values' Invalid JSON Expecting property name enclosed in double quotes line 1 column 3 char 2
- Error reading EKS Cluster couldn't find resource when running terraform plan
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.