0
votes

I have a task to send email with multiple attachments. S3 bucket will receive 2 files in same time approximately.

By using S3 bucket Put event, I am able to send email with single attachment by using lambda + SES.

Now the task is like,

I am getting 2 files in S3 like "XXXYYYZZZ" and "XXXYYYZZZ.20190712111820".

Prefix is same for both files and second file has name with its timestamp (20190712111820)

Here i need to send single email with above 2 files as attachment.

How to achieve it? I can understand Put Event will work on every new file gets created in S3.

1
Are you asking how to add 2 attachments to an email or how to handle the situation where your lambda gets triggered by each file and you don't know whether both exist at that time? - Jan Giacomelli
Thanks for the reply @giaco We can send multiple emails with multiple MIME. But the situation is like i need to pick 2 files and send single email.. I can understand it is not possible by using Event triggers.. Any way? - Karthik
Does those files always come in same order? - Jan Giacomelli
Yes it will come in same order - Karthik
If they always come in the same order you can filter events received from S3. For example: If you always get a file with suffix later, then you can check with regex if file has a suffix(while event from S3 contains key of file on S3). If it has it then you download file with suffix and file without suffix (you have the key just remove suffix) and add them as attachments. - Jan Giacomelli

1 Answers

0
votes

I was able to achieve solution for the same by attaching multiple MimeBodyPart into the message.

For each attachment, create MimeBodyPart attachment, read it and add it to the MimeMultipart.

It worked fine for me.