Search code examples
ruby-on-railsamazon-ses

How to upload attachment to application received via email?


I have a Rails Application (5.2.3).

There is a Model called Invoice.

The User can import Invoices through a view, uploading a XML file.

Now, the stakeholders are asking to have a mailbox where any User could send XML files, and the files will be automatically uploaded to the system.

The System is currently running on AWS, so a just created rule in the SES (SIMPLE EMAIL SERVICE) for a x@x.com mailbox to save all the messages in a S3 Bucket, to be parsed lather.

I could just do a plain script with everything(get files from S3, extract XML, Create Invoice) and schedule a runner. However, what is the Rails way for this kind of situation?

I read about Service Objects, but I'm not sure if it's the best place to have this task.

Thank you


Solution

  • You are talking about parsing inbound emails, e.g., Someone sends an attachment to upload@yourdomain.com and you want that attachment to be uploaded in your system. To achieve this, you need to configure your Amazon SES console properly and set an endpoint to your application which will handle the incoming webhook callback from your mail service with the content of the email. You can read more about this here

    https://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email.html

    Recieving emails with AWS SES/SNS