我使用 AWS 提供的这个功能作为教程:如何从存储在 S3 存储桶中的 Workmail 中读取文件
raw_msg = workmail_message_flow.get_raw_message_content(messageId=message_id)
parsed_msg: Message = email.message_from_bytes(raw_msg['messageContent'].read())
# Updating subject. For more examples, see https://github.com/aws-samples/amazon-workmail-lambda-templates.
parsed_msg.replace_header('Subject', f"[Hello World!] {subject}")
# Try to get the email bucket.
updated_email_bucket_name = os.getenv('UPDATED_EMAIL_S3_BUCKET')
if not updated_email_bucket_name:
print('UPDATED_EMAIL_S3_BUCKET not set in environment. '
'Please follow https://docs.aws.amazon.com/lambda/latest/dg/env_variables.html to set it.')
return
key = str(uuid.uuid4())
# Put the message in S3, so WorkMail can access it.
s3.put_object(Body=parsed_msg.as_bytes(), Bucket=updated_email_bucket_name, Key=key)
# Update the email in WorkMail.
s3_reference = {
'bucket': updated_email_bucket_name,
'key': key
}
content = {
's3Reference': s3_reference
}
每封电子邮件都保存在我的存储桶中,但我无法打开它并且没有类型,因此我无法将其转换为可读文本。
感谢您的时间!