从Amazon S3中存储的电子邮件中读取附件

时间:2018-04-26 13:27:25

标签: amazon-web-services amazon-s3 aws-lambda amazon-ses

请有人帮我帮忙..

我在S3中以原始格式存储电子邮件(这些电子邮件存储在S3中,从SES触发了一个触发器)..然后,当这些对象存储在S3中时,另一个Trigger调用lambda ..它工作正常.. 所以,这些电子邮件有附件..现在我想把这个attachaments存储在另一个S3桶中..我的lambda在nodejs ..有关如何阅读这个附件和存储在另一个桶中的任何建议?

我正在尝试这样的事情:

s3.getObject({
Bucket: src_bkt,
Key: src_key
}, function(err, data) {
        if (err) {
            console.log(err, err.stack);
            callback(err);
        } else {
            console.log('data')
            console.log(data)
            console.log("Raw text:\n" + data.Body.toString('ascii'));
            callback(null, null);
        }
    });   

所以在数据变量中我有S3文档..如果我做data.body.toString('ascii')我收到很多关于电子邮件的信息。包括这个:

From: ************** <************@gmail.com>
Date: Thu, 26 Apr 2018 12:52:51 +0000
Message-ID: <CAHj39+X87rSiuXoDatbKQeOM5izANYmQPh7Mw3zjrZe15guAkQ@mail.gmail.com>
Subject: teste
To: "**********@****.in" <**********@****.in>
Content-Type: multipart/mixed; boundary="000000000000291211056abfdea3"

--000000000000291211056abfdea3
Content-Type: multipart/alternative; boundary="00000000000029120e056abfdea1"

--00000000000029120e056abfdea1
Content-Type: text/plain; charset="UTF-8"

teste com anexo

--00000000000029120e056abfdea1
Content-Type: text/html; charset="UTF-8"

<div dir="ltr">teste com anexo</div>

--00000000000029120e056abfdea1--
--000000000000291211056abfdea3
Content-Type: application/octet-stream; name="K9A02AK.LPR"
Content-Disposition: attachment; filename="K9A02AK.LPR"
Content-Transfer-Encoding: base64
Content-ID: <163020361c0eb0cadbf1>
X-Attachment-Id: 163020361c0eb0cadbf1

TFBSMDAwMDEwICAgIFQgTEVUICAgICAgICAxIDI2MSA2NzMgICAwICAgMCAgIDEgICAwICAgMCAg
IDAgNzM3ICA3MzEgICAuICAwICAgMCAgIDAgICAwICAgMCAxMDANCiN/QQ0KIy8xLyAgICAgICAg
ICAgICAgICAgICAgICAgICAgQSAgIEcgICBEICAgLSAgIFIgICAtICAgVCAgIC0gICBaIFJFTEUg
RVguICBfICAgXyAgIF8gICBfICAgXyBDTEkNCkxQUiBmIDAwMDAgMjAxODA0MjYwOTEyNTQgTEVU
TklTU0FQIEFQU2VydmljZUxQUg0KTFBSIGUgMDAwNCAyMDE4MDQyNjA5MTI1OCBMRVROSVNTQVAg
QVBTZXJ2aWNlTFBSDQpMRVQgPCAwMDAwIDIwMTgwNDI2MDkxMzE4IExFVE5JU1NBUCBBUFNlcnZp
Y2VMUFINCkxQUiBFIDAwMDQgMjAxODA0MjYwOTEzMTkgTEVUTklTU0FQIEFQU2VydmljZUxQUg0K
--000000000000291211056abfdea3--

感谢。

1 个答案:

答案 0 :(得分:1)

现在正在运作.. 如果有人需要这样做:

使用mailparser lib:

self.toggle_selector.RS