Проблемы с отправкой по электронной почте панам данных с использованием AWS SES - PullRequest
1 голос
/ 20 сентября 2019

У меня есть фрейм данных Pandas, который я хотел бы отправить по электронной почте с помощью AWS Simple Email Service.

Я делаю фрейм данных так:

df = pd.DataFrame.from_records(listOfLists)
df_html = df.to_html()
send_email(df_html)

Вот как я пытаюсь на самом деле отправить фрейм данных:

import boto3
from botocore.exceptions import ClientError


def send_email(html_string):
    # Replace sender@example.com with your "From" address.
    # This address must be verified with Amazon SES.
    SENDER = "fake_email@fakeplace.com"

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

    # If necessary, replace us-west-2 with the AWS Region you're using for Amazon SES.
    AWS_REGION = "us-east-1"

    # 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 = f"""<html>
    <head></head>
    <body>
    {html_string}
    </body>
    </html> """

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

    # Create a new SES resource and specify a region.
    client = boto3.client('ses', region_name=AWS_REGION)

    # Try to send the email.
    try:
        # Provide the contents of the email.
        response = client.send_email(
            Destination={
                'ToAddresses': [
                    RECIPIENT,
                ],
            },
            Message={
                'Subject' : {'Data' : SUBJECT},
                'Body' : {
                    'Html' : {'Data' : BODY_HTML}
                }
            },
            Source=SENDER,
        )
    # 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'])

Вы заметите, что этоочень похожий пример, который вы видите здесь: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-sdk-python.html

Этот код создает только электронное письмо с пустым содержимым.Любое понимание того, почему это приведет к появлению пустого электронного письма, будет оценено.

...