无法在 aws ses 中设置 X-SES-CONFIGURATION-SET 标头

问题描述

我正在使用此脚本使用 AWS SES 发送电子邮件,我可以在收件箱中接收电子邮件,但在收到的电子邮件中看不到 X-SES-CONfigURATION-SET 标题。我还尝试使用 Simple 电子邮件正文类型 ConfigurationSetName 仍然没有运气。 非常感谢任何帮助。

import boto3
from botocore.exceptions import ClientError
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

# Replace sender@example.com with your "From" address.
# This address must be verified with Amazon SES.
SENDER = "Niranj Raja <niranj@xxx.com>"

# Replace recipient@example.com with a "To" address. If your account
# is still in the sandBox,this address must be verified.
RECIPIENT = "niranj@xxx.com"

# Specify a configuration set. If you do not want to use a configuration
# set,comment the following variable,and the
# ConfigurationSetName=CONfigURATION_SET argument below.
CONfigURATION_SET = "test-me"

# The subject line for the email.
SUBJECT = "Amazon SES Test (SDK for Python)"

# The email body for recipients with non-HTML email clients.
BODY_TEXT = ("Amazon SES Test (Python)\r\n"
             "This email was sent with Amazon SES using the "
             "AWS SDK for Python (Boto)."
             )

# The HTML body of the email.
BODY_HTML = """<html>
<head></head>
<body>
  <h1>Amazon SES Test (SDK for Python)</h1>
  <p>This email was sent with
    <a href='https://aws.amazon.com/ses/'>Amazon SES</a> using the
    <a href='https://aws.amazon.com/sdk-for-python/'>
      AWS SDK for Python (Boto)</a>.</p>
</body>
</html>
            """

# The character encoding for the email.
CHARSET = "UTF-8"

msg = MIMEMultipart('mixed')
# Add subject,from and to lines.
msg['Subject'] = SUBJECT
msg['From'] = SENDER
msg['To'] = RECIPIENT
#msg['X-SES-CONfigURATION-SET'] = CONfigURATION_SET

msg.add_header('X-SES-CONfigURATION-SET',CONfigURATION_SET)

print(dir(msg))

print('')
# Create a multipart/alternative child container.
msg_body = MIMEMultipart('alternative')
print(dir(msg_body))
# Encode the text and HTML content and set the character encoding. This step is
# necessary if you're sending a message with characters outside the ASCII range.
textpart = MIMEText(BODY_TEXT.encode(CHARSET),'plain',CHARSET)
htmlpart = MIMEText(BODY_HTML.encode(CHARSET),'html',CHARSET)

msg_body.attach(textpart)
msg_body.attach(htmlpart)

# Create a new SES resource and specify a region.
client = boto3.client(
            'sesv2',aws_access_key_id='test',aws_secret_access_key='test1',region_name='region-10'
        )

# Try to send the email.
try:
    # Provide the contents of the email.
    response = client.send_email(
        FromEmailAddress=SENDER,Destination={
            'ToAddresses': [
                RECIPIENT,],},Content={
            'Raw': {
               'Data': msg_body.as_string()
            }
        }
    )
    print(response)
# display an error if something goes wrong.
except ClientError as e:
    print(e.response['Error']['Message'])
else:
    print("Email sent! Message ID:"),print(response['MessageId'])

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)