샘플 수신 이메일 이벤트 - Amazon Simple Email Service

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

샘플 수신 이메일 이벤트

수신 이메일 이벤트를 Lambda 함수로 보내는 두 가지 방법이 있습니다. 첫 번째 방법은 Lambda 작업을 수신 규칙에 사용하여 이벤트 레코드를 함수로 직접 보내는 것입니다. 두 번째 방법은 Amazon SNS 작업을 수신 규칙에 사용하여 이벤트 레코드를 Amazon SNS로 보낸 후 Lambda 함수를 구독 엔드포인트로 Amazon SNS 주제에 추가하는 것입니다.

이 단원에는 Amazon SES에서 Lambda로 보낼 수 있는 이벤트 레코드의 예제가 나와 있습니다. 이 예제를 사용하여 테스트 Lambda 함수를 만들 수 있습니다.

참고

이 단원의 예제에는 줄 바꿈이 있어서 읽기 쉽습니다. 이 단원의 예제를 복사할 때는 추가 줄 바꿈을 제거해야 유효한 JSON 객체가 생깁니다.

Lambda 작업으로 제공되는 이벤트 레코드

Lambda 작업을 수신 규칙에 추가하면 수신 메시지를 받을 때마다 Amazon SES가 Lambda에 이벤트 레코드를 보냅니다. 수신 메시지의 여러 이메일 헤더에 대한 정보와 Amazon SES가 수신 메시지에 대해 수행하는 여러 테스트의 결과가 이 이벤트에 포함됩니다. 하지만 수신 이메일의 본문은 생략됩니다.

다음 예제에서는 이 이벤트 레코드에 일반적으로 포함되는 값을 보여줍니다.

{ "Records": [{ "eventSource": "aws:ses", "eventVersion": "1.0", "ses": { "mail": { "timestamp": "2019-08-05T21:30:02.028Z", "source": "prvs=144d0cba7=sender@example.com", "messageId": "EXAMPLE7c191be45-e9aedb9a-02f9-4d12-a87d-dd0099a07f8a-000000", "destination": ["recipient@example.com"], "headersTruncated": false, "headers": [{ "name": "Return-Path", "value": "<prvs=144d0cba7=sender@example.com>" }, { "name": "Received", "value": "from smtp.example.com [203.0.113.0]) by inbound-smtp.us-east-1.amazonaws.com with SMTP id bsvpsoklfhu7u50iur7h0kk9a2ou0r7iexample for recipient@example.com; Mon, 05 Aug 2019 21:30:02 +0000 (UTC)" }, { "name": "X-SES-Spam-Verdict", "value": "PASS" }, { "name": "X-SES-Virus-Verdict", "value": "PASS" }, { "name": "Received-SPF", "value": "pass (spfCheck: domain of example.com designates 203.0.113.0 as permitted sender) client-ip=203.0.113.0; envelope-from=prvs=144d0cba42=sender@example.com; helo= smtp.example.com;" }, { "name": "Authentication-Results", "value": "amazonses.com; spf=pass (spfCheck: domain of example.com designates 203.0.113.0 as permitted sender) client-ip=203.0.113.0; envelope-from=prvs=144d0cba42= sender@example.com; helo=smtp.example.com; dkim=pass header.i=@example.com; dmarc=none header.from=example.com;" }, { "name": "X-SES-RECEIPT", "value": "AEFBQUFBQUFBQUFHbFo0VU81VzVuYmRDNm51nhTVWpabDh6J4V2l5cG5PSHFtNzlBeUk90example" }, { "name": "X-SES-DKIM-SIGNATURE", "value": "a=rsa-sha256; q=dns/txt; b=Cm1emU30VcD6example=; c=relaxed/simple; s=6gbrjpgwjs 5zn6fwqknexample; d=amazonses.com; t=1567719002; v=1; bh=DSofsjAoUvyZj6YsBDP5en pRO1otGb7Nes0Qexample=; h=From:To:Cc:Bcc:Subject:Date:Message-ID:MIME-Version: Content-Type:X-SES-RECEIPT;" }, { "name": "DKIM-Signature", "value": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; i=@example.com; q=dns/txt; s=example12345; t=1567719001; x=1599255001; h=from:to:subject:date:message-id: references:in-reply-to:mime-version; bh=sjAoUvyZj6YsBDP5enpRO1otGb7s0Qexample=; b=EQw2D4RLOW2IHE9OgfEA4WXp+AENJtaD2+63wmd5J+d+t/xoaiKUGClOS7WhpyOmlipryOz+iOhxU v350xJIHjLTi9Jsnlw76mRK8o4770TaUz620joCVN21n4cxsrRZpv+1kS0EcAxaF30pmwlni+XT4ems Vxn7zO0I8example=;" }, { "name": "Received", "value": "from mail.example.com (mail.example.com [203.0.113.0]) by email-inbound-relay- 1d-9ec21598.us-east-1.example.com (Postfix) with ESMTPS id 57F83A2042 for <recipient@example.com>; Mon, 5 Aug 2019 21:29:58 +0000 (UTC)" }, { "name": "From", "value": "\"Doe, John\" <sender@example.com>" }, { "name": "To", "value": "\"recipient@example.com\" <recipient@example.com>" }, { "name": "Subject", "value": "This is a test" }, { "name": "Thread-Topic", "value": "This is a test" }, { "name": "Thread-Index", "value": "AQHVZDAaQ58yKI8q7kaAjkhC5stGexample" }, { "name": "Date", "value": "Mon, 5 Aug 2019 21:29:57 +0000" }, { "name": "Message-ID", "value": "<F8098FDD-49A3-442D-9935-F6112example@example.com>" }, { "name": "References", "value": "<1FCED16B-F6B0-4506-A6F0-594DFexample@example.com>" }, { "name": "In-Reply-To", "value": "<1FCED16B-F6B0-4506-A6F0-594DFexample@example.com>" }, { "name": "Accept-Language", "value": "en-US" }, { "name": "Content-Language", "value": "en-US" }, { "name": "X-MS-Has-Attach", "value": "" }, { "name": "X-MS-TNEF-Correlator", "value": "" }, { "name": "x-ms-exchange-messagesentrepresentingtype", "value": "1" }, { "name": "x-ms-exchange-transport-fromentityheader", "value": "Hosted" }, { "name": "x-originating-ip", "value": "[203.0.113.0]" }, { "name": "Content-Type", "value": "multipart/alternative; boundary=\"_000_F8098FDD49A344F6112B195BDAexamplecom_\"" }, { "name": "MIME-Version", "value": "1.0" }, { "name": "Precedence", "value": "Bulk" }], "commonHeaders": { "returnPath": "prvs=144d0cba7=sender@example.com", "from": ["\"Doe, John\" <sender@example.com>"], "date": "Mon, 5 Aug 2019 21:29:57 +0000", "to": ["\"recipient@example.com\" <recipient@example.com>"], "messageId": "<F8098FDD-49A3-442D-9935-F6112B195BDA@example.com>", "subject": "This is a test" } }, "receipt": { "timestamp": "2019-08-05T21:30:02.028Z", "processingTimeMillis": 1205, "recipients": ["recipient@example.com"], "spamVerdict": { "status": "PASS" }, "virusVerdict": { "status": "PASS" }, "spfVerdict": { "status": "PASS" }, "dkimVerdict": { "status": "PASS" }, "dmarcVerdict": { "status": "GRAY" }, "action": { "type": "Lambda", "functionArn": "arn:aws:lambda:us-east-1:123456789012:function:IncomingEmail", "invocationType": "Event" } } } }] }

Amazon SNS 작업으로 제공되는 이벤트 레코드

Amazon SNS 작업을 수신 규칙에 추가하면 이메일의 전체 내용이 알림에 포함됩니다. Lambda 함수가 이메일 본문을 처리하게 하려면 Amazon SNS 작업을 대신 수신 규칙에 추가해야 합니다. 그런 다음 Amazon SNS에서 Lambda 함수를 Amazon SNS 함수에 구독합니다. 이렇게 구성하면 Amazon SNS 주제에서 알림을 받을 때 Lambda 함수가 활성화됩니다.

{ 'Records': [ { 'EventSource': 'aws:sns', 'EventVersion': '1.0', 'EventSubscriptionArn': 'arn:aws:sns:us-east-1:123456789012:IncomingEmail:12345678', 'Sns': { 'Type': 'Notification', 'MessageId': 'EXAMPLE7c191be45-e9aedb9a-02f9-4d12-a87d-dd0099a07f8a-000000', 'TopicArn': 'arn:aws:sns:us-east-1:123456789012:IncomingEmail', 'Subject': 'Amazon SES Email Receipt Notification', 'Message': <message content—see below>, 'Timestamp': '2019-09-06T18:52:16.076Z', 'SignatureVersion': '1', 'Signature': '012345678901example==', 'SigningCertUrl': 'https://sns.us-east-1.amazonaws.com/SimpleNotificationService -01234567890123456789012345678901.pem', 'UnsubscribeUrl': 'https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe& SubscriptionArn=arn:aws:sns:us-east-1:0123456789012:IncomingEmail: 0b863538-3f32-462e-9c89-8d8e0example', 'MessageAttributes': {} } } ] }

Message 속성에는 JSON으로 인코딩된 문자열이 포함됩니다. 이 문자열에는 메시지의 헤더 및 콘텐츠가 포함되어 있습니다. 메시지 본문 자체는 base64로 인코딩됩니다. Lambda 함수에 메시지 본문을 사용하려면 먼저 Message 속성을 디코딩한 다음 Content 객체를 디코딩해야 합니다.

다음 예제에서는 Message 속성에 포함된 값을 보여줍니다.

{ "notificationType": "Received", "mail": { "timestamp": "2019-09-06T18:52:14.965Z", "source": "0100016d07eb7477-8e1938ce-475e-4e4b-89cb-example-000000@amazonses.com", "messageId": "12345678901example", "destination": ["recipient@example.com"], "headersTruncated": false, "headers": [{ "name": "Return-Path", "value": "<0100016d07eb7477-8e1938ce-475e-4e4b-89cb-example-000000@amazonses.com>" }, { "name": "Received", "value": "from a1-23.smtp-out.amazonses.com (a1-23.smtp-out.amazonses.com [203.0.113.0]) by inbound-smtp.us-east-1.amazonaws.com with SMTP id 12345678901example for recipient@example.com; Fri, 06 Sep 2019 18:52:14 +0000 (UTC)" }, { "name": "X-SES-Spam-Verdict", "value": "PASS" }, { "name": "X-SES-Virus-Verdict", "value": "PASS" }, { "name": "Received-SPF", "value": "pass (spfCheck: domain of amazonses.com designates 203.0.113.0 as permitted sender) client-ip=203.0.113.0; envelope-from=0100016d07eb7477-8e1938ce-475e-4e4b-89cb-example -000000@amazonses.com; helo=a1-23.smtp-out.amazonses.com;" }, { "name": "Authentication-Results", "value": "amazonses.com; spf=pass (spfCheck: domain of amazonses.com designates 203.0.113.0 as permitted sender) client-ip=203.0.113.0; envelope-from=0100016d07eb7477-8e1938ce -475e-4e4b-89cb-example-000000@amazonses.com; helo=a1-23.smtp-out.amazonses.com; dkim=pass header.i=@amazonses.com; dmarc=none header.from=example.com;" }, { "name": "X-SES-RECEIPT", "value": "AEFBQUFBQUFBQUFFQkx0QUJZZENEXAMPLE=" }, { "name": "X-SES-DKIM-SIGNATURE", "value": "a=rsa-sha256; q=dns/txt; b=d5azwgA2iBqAjA4NBm1ARzjJ95raRmy4G84iVdd3x2JzSHeUnQuTuLmJ AqRrYY3WpMIVRFy01hITaguCVjUPWBR0xF6fCEXH85cf3RNeFQyLfWZqoXKfBdjFRV+13troDterH2MxBUL 8rjzcvdHetl0ImwlaK2PGmePTexample=; c=relaxed/simple; s=EXAMPLE7c191be45-e9aedb9a-02 f9-4d12-a87d-dd0099a07f8a-000000; d=amazonses.com; t=1567795935; v=1; bh=CZ1SghsYaA 6SSCbitzsLISeFoNlpdtH1Pyiexample=; h=From:To:Cc:Bcc:Subject:Date:Message-ID:MIME- Version:Content-Type:X-SES-RECEIPT;" }, { "name": "DKIM-Signature", "value": "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=EXAMPLE7c191be45-e9aedb9a-02f9- 4d12-a87d-dd0099a07f8a-000000; d=amazonses.com; t=1567795934; h=From:To:Subject: MIME-Version:Content-Type:Message-ID:Date:Feedback-ID; bh=CZ1SghsYaA6SSCbitzsLISeFo NlpdtH1Pyiexample=; b=L6VXqR1PSN/FYqJI/VAfPRKFgtakcHCYJvuJqVYbuJT8I3FOhqOvkbcgHxOgs woxPfvGrL6S53H8Er5Do/CPvOM4Tx3ilE+a0GTYVLjKmwltNeN09YWlJAoqG5KMQPZUxRYaNvYPInLzUdGi rdjkbSIgZEnrvq5MzaMWexample=" }, { "name": "From", "value": "sender@example.com" }, { "name": "To", "value": "recipient@example.com" }, { "name": "Subject", "value": "Amazon SES Test" }, { "name": "MIME-Version", "value": "1.0" }, { "name": "Content-Type", "value": "multipart/alternative; boundary=\"----=_Part_869787_396523212.15677example\"" }, { "name": "Message-ID", "value": "<0100016d07eb7477-8e1938ce-475e-4e4b-89cb-example-000000@email.amazonses.com>" }, { "name": "Date", "value": "Fri, 6 Sep 2019 18:52:14 +0000" }, { "name": "X-SES-Outgoing", "value": "2019.09.06-203.0.113.0" }, { "name": "Feedback-ID", "value": "1.us-east-1.ZitRoTk0xziun8WEJevt+cSJ17QNuCwulg2D2v3nrT0=:AmazonSES" }], "commonHeaders": { "returnPath": "0100016d07eb7477-8e1938ce-475e-4e4b-89cb-example-000000@amazonses.com", "from": ["sender@example.com"], "date": "Fri, 6 Sep 2019 18:52:14 +0000", "to": ["recipient@example.com"], "messageId": "<0100016d07eb7477-8e1938ce-475e-4e4b-89cb-example-000000@email.amazonses.com>", "subject": "Amazon SES Test" } }, "receipt": { "timestamp": "2019-09-06T18:52:14.965Z", "processingTimeMillis": 1098, "recipients": ["recipient@example.com"], "spamVerdict": { "status": "PASS" }, "virusVerdict": { "status": "PASS" }, "spfVerdict": { "status": "PASS" }, "dkimVerdict": { "status": "GRAY" }, "dmarcVerdict": { "status": "GRAY" }, "action": { "type": "SNS", "topicArn": "arn:aws:sns:us-east-1:123456789012:IncomingEmail", "encoding": "BASE64" } }, "content": "UmV0dXJuLVBhdGg6IDwwMTAwMDE2ZDA3ZWI3NDc3LThlMTkzOGNlLTQ3NWUtNGU0Yi04OWNiLWV4YW1wbGUtM DAwMDAwQGFtYXpvbnNlcy5jb20+ClJlY2VpdmVkOiBmcm9tIGExLTIzLnNtdHAtb3V0LmFtYXpvbnNlcy5jb2 0gKGExLTIzLnNtdHAtb3V0LmFtYXpvbnNlcy5jb20gWzIwMy4wLjExMy4wXSkKIGJ5IGluYm91bmQtc210cC5 1cy1lYXN0LTEuYW1hem9uYXdzLmNvbSB3aXRoIFNNVFAgaWQgZW5xMTBpYW1lMXFjdTMxamg1ZGEyZ244OWlt dm90Mms2ZXhhbXBsZQogZm9yIHJlY2lwaWVudEBleGFtcGxlLmNvbTsKIEZyaSwgMDYgU2VwIDIwMTkgMTg6N TI6MTQgKzAwMDAgKFVUQykKWC1TRVMtU3BhbS1WZXJkaWN0OiBQQVNTClgtU0VTLVZpcnVzLVZlcmRpY3Q6IF BBU1MKUmVjZWl2ZWQtU1BGOiBwYXNzIChzcGZDaGVjazogZG9tYWluIG9mIGFtYXpvbnNlcy5jb20gZGVzaWd uYXRlcyAyMDMuMC4xMTMuMCBhcyBwZXJtaXR0ZWQgc2VuZGVyKSBjbGllbnQtaXA9MjAzLjAuMTEzLjA7IGVu dmVsb3BlLWZyb209MDEwMDAxNmQwN2ViNzQ3Ny04ZTE5MzhjZS00NzVlLTRlNGItODljYi1leGFtcGxlLTAwM DAwMEBhbWF6b25zZXMuY29tOyBoZWxvPWExLTIzLnNtdHAtb3V0LmFtYXpvbnNlcy5jb207CkF1dGhlbnRpY2 F0aW9uLVJlc3VsdHM6IGFtYXpvbnNlcy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