Script to save and rename attatchment from an email

2

I have a software that sends an email with a CSV file attached with data from all the printers in the network once a week.
I have it installed in multiple places so I receive multiple files with the same name.

I need to schedule a script that saves the attached csv files in a folder in my ubuntu server, unfortunately I cannot configure the name of the file sent at the source and all the files need to have different names so:

  • download the email in my Ubuntu server
  • save and rename based on the address of the sender the attachments in a local folder (overwriting the old one)
  • delete the email it just downloaded

I'm aware of fetchmail and munpack but I'm not 100% sure if it allows renaming and that's a crucial point of the whole thing.
Is this thing possible with just bash command?

Nicola Pertici

Posted 2018-06-26T07:19:34.687

Reputation: 21

Why don't you rename the file with an mv command after receiving it? – xenoid – 2018-06-26T08:40:39.747

@xenoid the server has to do it automatically without supervision and I don't know if there's some sort of foreach i can use with the file retreived with fetchmail in case of multiple emails. – Nicola Pertici – 2018-06-26T13:06:58.550

No answers