15

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=?=

vinayvinay
  • 151
  • 1
  • 1
  • 6

4 Answers4

5

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.

James Bowler
  • 2,194
  • 2
  • 17
  • 23
4

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,
    )
Hrabal
  • 2,403
  • 2
  • 20
  • 30
  • 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:"target@example.com"`, which should be `Reply-To:target@example.com`. – coredumperror May 13 '22 at 22:16
  • 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? – AppDreamer Jul 13 '22 at 15:53
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="some_user@domain.com"

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

Dwayne Driskill
  • 1,470
  • 1
  • 13
  • 19
0

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 <foo@bar.com>"
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", "foo@bar.com"))
print(message2.as_string())
# To: =?utf-8?q?Recipi=C3=A9nt?= <foo@bar.com>
brianmaissy
  • 394
  • 5
  • 9