当前位置:  开发笔记 > 编程语言 > 正文

AWS SES S3处理入站电子邮件

如何解决《AWSSESS3处理入站电子邮件》经验,为你挑选了2个好方法。

我正在开发基于AWS SES的电子邮件系统发布.对于所有传入的电子邮件,我设置路由以将消息保存在S3存储桶中,以便我可以异步处理它们.我遇到的问题是消息以原始格式保存在S3存储桶中:标题,电子邮件正文等+加密附件(一个巨大的字符串) - 全部在一个文件中.

有没有办法将电子邮件消息从附件中分离出来并将它们保存在AWS SES级别的单独文件中?我正在尝试直接从AWS获取我需要的格式的数据,并避免在流程中添加另一个处理步骤.

如果AWS SES不提供此类功能,那么处理这些消息以获得上述结果的正确方法是什么?



1> Mark B..:

让SES自动为您分割电子邮件似乎不可能.根据此处的文档:

Amazon SES为您提供未经修改的原始电子邮件,通常采用多用途Internet邮件扩展(MIME)格式.

当SES将新的电子邮件文件发送到S3时,我会使用S3或SNS来触发Lambda函数.Lambda函数可以根据需要拆分文件,然后将这些新文件写入另一个S3存储桶.


是否有任何您知道的文档可能描述如何创建Lambda函数?我有收到SES的电子邮件,我只需要将附件复制到S3.

2> Sajith Sanka..:

对于稍后回到此问题的任何人,这是从SES调用Lambda函数时获得的JSON结构的链接.

http://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email-notifications-examples.html

它需要一些搜索才能到达那个页面;-)

从链接中,Lambda通知看起来像这样,

{
"notificationType": "Received",
"receipt": {
    "timestamp": "2015-09-11T20:32:33.936Z",
    "processingTimeMillis": 406,
    "recipients": [
        "recipient@example.com"
    ],
    "spamVerdict": {
        "status": "PASS"
    },
    "virusVerdict": {
        "status": "PASS"
    },
    "spfVerdict": {
        "status": "PASS"
    },
    "dkimVerdict": {
        "status": "PASS"
    },
    "action": {
        "type": "S3",
        "topicArn": "arn:aws:sns:us-east-1:012345678912:example-topic",
        "bucketName": "my-S3-bucket",
        "objectKey": "\email"
    }
},
"mail": {
    "timestamp": "2015-09-11T20:32:33.936Z",
    "source": "0000014fbe1c09cf-7cb9f704-7531-4e53-89a1-5fa9744f5eb6-000000@amazonses.com",
    "messageId": "d6iitobk75ur44p8kdnnp7g2n800",
    "destination": [
        "recipient@example.com"
    ],
    "headersTruncated": false,
    "headers": [
        {
            "name": "Return-Path",
            "value": "<0000014fbe1c09cf-7cb9f704-7531-4e53-89a1-5fa9744f5eb6-000000@amazonses.com>"
        },
        {
            "name": "Received",
            "value": "from a9-183.smtp-out.amazonses.com (a9-183.smtp-out.amazonses.com [54.240.9.183]) by inbound-smtp.us-east-1.amazonaws.com with SMTP id d6iitobk75ur44p8kdnnp7g2n800 for recipient@example.com; Fri, 11 Sep 2015 20:32:33 +0000 (UTC)"
        },
        {
            "name": "DKIM-Signature",
            "value": "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=ug7nbtf4gccmlpwj322ax3p6ow6yfsug; d=amazonses.com; t=1442003552; h=From:To:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Message-ID:Feedback-ID; bh=DWr3IOmYWoXCA9ARqGC/UaODfghffiwFNRIb2Mckyt4=; b=p4ukUDSFqhqiub+zPR0DW1kp7oJZakrzupr6LBe6sUuvqpBkig56UzUwc29rFbJF hlX3Ov7DeYVNoN38stqwsF8ivcajXpQsXRC1cW9z8x875J041rClAjV7EGbLmudVpPX 4hHst1XPyX5wmgdHIhmUuh8oZKpVqGi6bHGzzf7g="
        },
        {
            "name": "From",
            "value": "sender@example.com"
        },
        {
            "name": "To",
            "value": "recipient@example.com"
        },
        {
            "name": "Subject",
            "value": "Example subject"
        },
        {
            "name": "MIME-Version",
            "value": "1.0"
        },
        {
            "name": "Content-Type",
            "value": "text/plain; charset=UTF-8"
        },
        {
            "name": "Content-Transfer-Encoding",
            "value": "7bit"
        },
        {
            "name": "Date",
            "value": "Fri, 11 Sep 2015 20:32:32 +0000"
        },
        {
            "name": "Message-ID",
            "value": "<61967230-7A45-4A9D-BEC9-87CBCF2211C9@example.com>"
        },
        {
            "name": "X-SES-Outgoing",
            "value": "2015.09.11-54.240.9.183"
        },
        {
            "name": "Feedback-ID",
            "value": "1.us-east-1.Krv2FKpFdWV+KUYw3Qd6wcpPJ4Sv/pOPpEPSHn2u2o4=:AmazonSES"
        }
    ],
    "commonHeaders": {
        "returnPath": "0000014fbe1c09cf-7cb9f704-7531-4e53-89a1-5fa9744f5eb6-000000@amazonses.com",
        "from": [
            "sender@example.com"
        ],
        "date": "Fri, 11 Sep 2015 20:32:32 +0000",
        "to": [
            "recipient@example.com"
        ],
        "messageId": "<61967230-7A45-4A9D-BEC9-87CBCF2211C9@example.com>",
        "subject": "Example subject"
    }
}
}


请注意,这是传递给Lambda的事件.这不是实际的电子邮件本身,因此没有"正文".如果您不需要它并且您可以使用所提供的功能,那很好,但如果您需要`body`,您可能需要将SES电子邮件保存到S3,从此事件中获取文件名(密钥),从S3读取电子邮件,然后解析文件内容(MIME电子邮件格式)以拉出`body`.
推荐阅读
低调pasta_730
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有