1

If I try to use Boto 3 to send an email with SES with a Reply-To header that doesn't match some other header in the email, using a script like this...

import boto3
client = boto3.client('ses')
client.send_email(
    Destination={
        'ToAddresses': [
            "someone@example.com"
        ],
        'ReplyToAddresses': [
            "someoneelse@example.com"
        ]
    },
    Message={
        'Body': {
            'Text': {
                'Charset': "UTF-8",
                'Data': 'Bla bla bla',
            },
        },
        'Subject': {
            'Charset': "UTF-8",
            'Data': 'Bla bla bla',
        },
    },
    Source="My Company <noreply@example.com>",
)

... then I receive an error like this:

Traceback (most recent call last):
  File "/Users/markamery/test.py", line 24, in <module>
    Source="My Company <noreply@shielddx.com>",
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/botocore/client.py", line 320, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/botocore/client.py", line 596, in _make_api_call
    api_params, operation_model, context=request_context)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/botocore/client.py", line 632, in _convert_to_request_dict
    api_params, operation_model)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/botocore/validate.py", line 291, in serialize_to_request
    raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Unknown parameter in Destination: "ReplyToAddresses", must be one of: ToAddresses, CcAddresses, BccAddresses

This doesn't make much sense to me. What I'm trying to do here seems to be a best practice (see https://stackoverflow.com/a/14555043/1709587) and according to https://forums.aws.amazon.com/thread.jspa?threadID=60093&tstart=0, as of 2011, you can use "any email address" in the "Reply-To" header.

What causes this error? Have SES's rules been changed again since that forum post from 2011? Is the error I see above an undocumented restriction for accounts that are in the sandbox, like mine? Or is this a bug - is Boto 3, on the client side, applying stricter validation of ReplyToAddresses than the AWS API itself does?

Mark Amery
  • 143,130
  • 81
  • 406
  • 459

1 Answers1

1

According to the boto3 docs you need to put the list of reply-to adresses in an argument outside of the Destinations argument. It seems strange to me too.

send_mail(
    ...,
    Destination={...},
    ReplyToAddresses=[
        'someoneelse@example.com',
])
Taek
  • 1,004
  • 7
  • 20
  • Oh man, I'm an idiot. I would delete this question out of embarrassment, except that perhaps somebody else will make the same mistake and benefit from it. This actually makes perfect sense; the `Reply-To` address is not a *destination* for the email, so doesn't logically belong in the `Destination` parameter. I was misinterpreting the error message to mean that one of my `Reply-To` addresses was "unknown" by virtue of not being included in the destinations list, when *really* it was telling my that the *parameter name* `ReplyToAddresses` was "unknown". Suddenly the error makes total sense. – Mark Amery Nov 19 '18 at 17:19