Looks like Amazon SES has started supporting receiving emails: http://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email-consider-use-case.html
The received email can configured to be saved to S3. Does it support receiving attachments in the received email as well? Any information on how attachment gets saved to S3 and how is it retrieved?
Yes, by creating a receipt rule, and defining an action to save the message to S3, you can retrieve an email message and its attachment as an S3 object from the bucket specified in the rule.
For example, if you specify a rule for recipient, [email protected], and assign an S3 Action to write to S3 bucket call sms-example.com under the prefix, messages will be delivered to that bucket for that recipient.
As described in http://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email-consider-use-case.html:
Amazon SES delivers you the raw, unmodified email, which is typically in Multipurpose Internet Mail Extensions (MIME) format. For more information about MIME format, see RFC 2045.
That means attachments will be encoded in MIME format, as a Multipart Message
Since the email is delivered as raw MIME email, you need to parse the file, and extract the attachments. Here is an example of what an email with attachments would look like:
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=frontier
This is a message with multiple parts in MIME format.
--frontier
Content-Type: text/plain
This is the body of the message.
--frontier
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64
PGh0bWw+CiAgPGhlYWQ+CiAgPC9oZWFkPgogIDxib2R5PgogICAgPHA+VGhpcyBpcyB0aGUg
Ym9keSBvZiB0aGUgbWVzc2FnZS48L3A+CiAgPC9ib2R5Pgo8L2h0bWw+Cg==
--frontier--
You can see the attachment where Content-Type: application/octet-stream
starts. The attachment is encoded in base64.
See RFC 2045 Multipurpose Internet Mail Extensions
Here is a complete message as delivered to S3, including a JPG attachment named "example.jpg". It was delivered to the following S3 location: https://s3.amazonaws.com/sms-example.com/messages/jldcn43gv5tt9qvhuia34ihodm6erpmqe3l7ghg1. The object name is taken from the SMTP id provided by the message.
Return-Path: <[email protected]>
Received: from mx6.example.com (mx6.example.com [255.255.245.6])
by inbound-smtp.us-east-1.amazonaws.com with SMTP id jldcn43gv5tt9qvhuia34ihodm6erpmqe3l7ghg1
for [email protected];
Thu, 27 Jul 2017 16:53:34 +0000 (UTC)
X-SES-Spam-Verdict: PASS
X-SES-Virus-Verdict: PASS
Received-SPF: softfail (spfCheck: transitioning domain of example.com does not designate 255.255.245.6 as permitted sender) client-ip=255.255.245.6; [email protected]; helo=mx6.example.com;
Authentication-Results: amazonses.com;
spf=softfail (spfCheck: transitioning domain of example.com does not designate 255.255.245.6 as permitted sender) client-ip=255.255.245.6; [email protected]; helo=mx6.example.com;
X-SES-RECEIPT: AEFBQUFBQUFBQUFHbmZUa1QwOTA4N1dQc2ZiRGFQMTFMdzBNdzNkWG1uMEFEaGpIeEo4eHRuWUIrZUp3ZzJwK1RhZE1sWDhGY0RGWUg3Q2Q2U25Eb3BjNVVtTnhNQjVaWWhUN3c1NU4yWDRHMUxrNFlaRTRzcFU4aE5MbDZWUnBuVEdXN1VsNExBa2hrUHBMQnlPN1hDdzZnZXB1ek53MkwvZkVUcHpiZ3hJK2hESmNNUm5sNGxPazNMYnQrSG11UjY0djFxZ2VBalF6QlhZRnlWdWdQamcwTzlNN2xHZEticG5oZUQ1ZFVoTC9WWUtiZjY5amhkMTlRd1BWbUkyMnpIbmJUb0xpMzhVTlBMSzBqZzI3MFZHVFQvcU5CaHA0Rw==
X-SES-DKIM-SIGNATURE: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple;
s=224i4yxa5dv7c2xz3womw6peuasteono; d=amazonses.com; t=1501174414;
h=X-SES-RECEIPT:Date:Subject:Message-ID:From:To:MIME-Version:Content-Type;
bh=Kf3QaHVBBiEvy382/1pLBxRFSsmLtlEpffsi6Kju+B4=;
b=h8+aAxvaaTyhF1HrkKjx7wWmdZ9IZ1wBAhULLQ6Yrf2ILYgiI5dWReJ5pZ5B3gkz
IBTbMyLoX5/8mAxHck0OT8mHs7phuIh0kad3Aioel92PYKeVkr+k33/dQmD3B5r5UKn
VEM41uSKQu2rGwB5CuAIgoGmKYMyeXnmX+bi6JL0=
X-Footer: a21zbXguY29t
Received: from mx4.example.com ([192.99.225.232])
(authenticated user [email protected])
by mx6.example.com (Mailer 9.2.3) with ESMTPSA
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits))
for [email protected];
Thu, 27 Jul 2017 10:53:30 -0600
X-Footer: ZG9qaWdneS5jb20=
Received: from localhost ([127.0.0.1])
by mx4.example.com (Mailer 9.2.3) with ESMTPSA
for [email protected];
Thu, 27 Jul 2017 10:53:04 -0600
Date: Thu, 27 Jul 2017 10:53:04 -0600
Subject: attachment
X-Mailer: Mailer 9.2.3/Mailer Client
X-User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36
Message-ID: <[email protected]>
From: User <[email protected]>
To: [email protected]
X-Priority: 3
Importance: Normal
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-u4HpRD436UcA8Yj9oMVl"
--=-u4HpRD436UcA8Yj9oMVl
Content-Type: multipart/alternative; boundary="=-89WEH0obI4GHeo+VHXBi"
--=-89WEH0obI4GHeo+VHXBi
Content-Type: text/plain; charset="utf-8"
--=-89WEH0obI4GHeo+VHXBi
Content-Type: text/html; charset="utf-8"
<html><head></head><body></body></html>
--=-89WEH0obI4GHeo+VHXBi--
--=-u4HpRD436UcA8Yj9oMVl
Content-Type: image/jpeg; name="example.jpg"
Content-Disposition: attachment; filename="example.jpg"
Content-Transfer-Encoding: base64
/9j/4AAQSkZJRgABAQEAYABgAAD/4RDaRXhpZgAATU0AKgAAAAgABAE7AAIAAAAFAAAISodpAAQA
AAABAAAIUJydAAEAAAAKAAAQyOocAAcAAAgMAAAAPgAAAAAc6gAAAAgAAAAAAAAAAAAAAAAAAAAA
--=-u4HpRD436UcA8Yj9oMVl--
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With