Getting "InvalidParameterValue - Missing final '@domain'" from Amazon SES while sending an email with unicode characters in destination address
Asked Answered
G

5

19

Amazon SES returns the error mentioned above when i try to send an email that contains unicode characters in the To: field. Amazon SES Documentation says that such email addresses should be sent in MIME encoded-word syntax, which the mail gem (used by ActionMailer) is doing correctly, it is sent as: =?UTF-8?B?dmluYXl2aW5heeKAmXNAbWFpbGluYXRvci5jb20=?=

Groscr answered 23/1, 2014 at 10:28 Comment(1)
Resolved my issue, I included 'no-reply@domain-name' or 'admin@domain' instead of solely using the domain name.Pedagogue
A
8

I was seeing this same error, and found it was due to an incorrect ReturnPath parameter. The error indicates your ReturnPath parameter does not have a domain name. The ReturnPath parameter should be an email address, and it's the address to which bounce notifications are forwarded.

Albertalberta answered 4/3, 2014 at 21:40 Comment(1)
Populating ReturnPath parameter didn't fix it for me. Must be something else.Crone
M
5

The question is pretty old, but I'll add my case for it seems to be the first result searching for problems with "Missing finale @domain" on AWS SES.

(the only other SO question I found is AWS SES Missing final '@domain' PHP SDK )

As in the other question's answer, InvalidParameterValue is returned every time a parameter don't pass validation.

In my case I was using boto3 on python, composing the Destination parameter with some keys that could be empty, like so:

to = []
bcc = []
# Some code to populate one or both lists..
response = client.send_email(
        Destination={
            'ToAddresses': to,
            'BccAddresses': bcc
        },
        Message={
            'Body': {
                'Html': {
                    'Charset': MAIL_CHARSET,
                    'Data': message,
                },
                'Text': {
                    'Charset': MAIL_CHARSET,
                    'Data': message,
                },
            },
            'Subject': {
                'Charset': MAIL_CHARSET,
                'Data': subject,
            },
        },
        Source=MAIL_SENDER,
    )

If one of the two keys in the dict assigned to the Destination parameter was an empty list the InvalidParameterValue was returned. Solution is to simply remove empty, useless, key:

to = []
bcc = []
# Some code to populate one or both lists..
destinations = {
            'ToAddresses': to,
            'BccAddresses': bcc
        }
response = client.send_email(
        Destination={typ: addresses
                     for typ, addresses in destinations.iteritems()
                     if addresses},
        Message={
            'Body': {
                'Html': {
                    'Charset': MAIL_CHARSET,
                    'Data': message,
                },
                'Text': {
                    'Charset': MAIL_CHARSET,
                    'Data': message,
                },
            },
            'Subject': {
                'Charset': MAIL_CHARSET,
                'Data': subject,
            },
        },
        Source=MAIL_SENDER,
    )
Mu answered 15/4, 2018 at 10:26 Comment(2)
Thank you! This ended up helping me find the source of my own similar problem. Though in my case, I was accidentally quoting the Reply-To header's email value, e.g. Reply-To:"[email protected]", which should be Reply-To:[email protected].Bluing
Interesting... we just started getting this error. In code that has worked for years, we had a line copied form the AWS example: ReplyToAddresses: [ /* more items */ ] Is it possible that AWS has added a check for the value being legit and is it now required?Coinsurance
P
1

I was getting this error when using the SES SendRawEmail API because my entire "To" header was being encoded in MIME encoded-words syntax as a unit.

It's not completely clear from the documentation, but it hints that the sender name should be encoded separately.

The sender name (also known as the friendly name) may contain non-ASCII characters. These characters must be encoded using MIME encoded-word syntax, as described in RFC 2047. MIME encoded-word syntax uses the following form: =?charset?encoding?encoded-text?=.

source: https://docs.aws.amazon.com/ses/latest/APIReference/API_SendRawEmail.html#:~:text=The%20sender%20name,encoded%2Dtext%3F%3D.

Python's email.message.Message class automatically encodes headers containing non-ascii characters as a single chunk:

from email.message import Message

message1 = Message()
message1["To"] = "Recipiént <[email protected]>"
print(message1.as_string())
# To: =?utf-8?b?UmVjaXBpw6ludCA8Zm9vQGJhci5jb20+?=

I worked around this by formatting the address in advance using the formataddr utility function, which does the encoding for the sender name separately:

from email.utils import formataddr

message2 = Message()
message2["To"] = formataddr(("Recipiént", "[email protected]"))
print(message2.as_string())
# To: =?utf-8?q?Recipi=C3=A9nt?= <[email protected]>
Pinfeather answered 7/11, 2022 at 12:9 Comment(0)
R
0

I just got this error because I was storing email addresses in a .cfg file (which uses the same structure as a Windows .ini file) and I put quotes around the email address like programmers are in the habit of doing with strings but that you shouldn't do in a cfg file:

[email_settings]
email_to="[email protected]"

When I removed the quotes, it worked. I'm sure there are multiple issues that can cause this error.

Randallrandan answered 26/1, 2021 at 21:13 Comment(0)
A
0

I think this error might have occurred for different reasons. So it might be possible that there may be case-specific reasons, and one solution might not work every time.

I'm using the @aws-sdk/client-ses JS SDK. In my case, I was facing it while providing an address as an empty string, null, or undefined.

Animate answered 8/3 at 6:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.