发送目标地址中包含 unicode 字符的电子邮件时,从 Amazon SES 获取“InvalidParameterValue - Missing Final '@domain'”

问题描述 投票:0回答:5

当我尝试发送“收件人:”字段中包含 unicode 字符的电子邮件时,Amazon SES 返回上述错误。 Amazon SES 文档指出此类电子邮件地址应以 MIME 编码字语法发送,邮件 gem(ActionMailer 使用的)正确执行此操作,发送方式为: =?UTF-8?B?dmluYXl2aW5heeKAmXNAbWFpbGluYXRvci5jb20=?=

amazon-web-services amazon-ses
5个回答
6
投票

我看到了同样的错误,发现这是由于 ReturnPath 参数不正确造成的。该错误表明您的 ReturnPath 参数没有域名。 ReturnPath 参数应该是一个电子邮件地址,它是退回邮件通知转发到的地址。


5
投票

这个问题相当老了,但我会添加我的案例,因为它似乎是在 AWS SES 上搜索“Missing Finale @domain”问题的第一个结果。

(我发现的唯一其他问题是 AWS SES 缺少最终的“@domain”PHP SDK )

与另一个问题的答案一样,每次参数未通过验证时都会返回 InvalidParameterValue。

在我的例子中,我在 python 上使用 boto3,用一些可能为空的键组成 Destination 参数,如下所示:

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,
    )

如果分配给 Destination 参数的字典中的两个键之一是空列表,则返回 InvalidParameterValue。 解决方案是简单地删除空的、无用的键:

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,
    )

1
投票

我在使用 SES

SendRawEmail
API 时遇到此错误,因为我的整个“To”标头都以 MIME 编码单词语法 作为一个单元进行编码。

文档中并不完全清楚,但它暗示发件人姓名应该单独编码。

发件人名称(也称为友好名称)可能包含非 ASCII 字符。这些字符必须使用 MIME 编码字语法进行编码,如 RFC 2047 中所述。MIME 编码字语法使用以下形式:=?charset?encoding?encoded-text?=.

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

Python 的

email.message.Message
类自动将包含非 ASCII 字符的标头编码为单个块:

from email.message import Message

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

我通过使用

formataddr
实用函数提前格式化地址来解决这个问题,该函数单独对发件人姓名进行编码:

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]>

0
投票

我刚刚收到此错误,因为我将电子邮件地址存储在 .cfg 文件中(该文件使用与 Windows .ini 文件相同的结构),并且我在电子邮件地址周围加上引号,就像程序员习惯使用字符串一样,但是你不应该在 cfg 文件中这样做:

[email_settings]
email_to="[email protected]"

当我删除引号时,它起作用了。我确信有多个问题可能导致此错误。


0
投票

我认为这个错误可能是由于不同的原因而发生的。因此,可能存在具体情况的原因,并且一种解决方案可能并非每次都有效。

我正在使用

@aws-sdk/client-ses
JS SDK。就我而言,我在提供空字符串、null 或未定义地址时遇到了这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.