3

How do I extract attachments from mails arriving at my postfix mailbox and preferably send the content of the attachment to another email account? I am interested in being able to acquire/read the content of the attachment on ubuntu terminal.

Timo
  • 6,202
  • 1
  • 26
  • 28
user40952
  • 467
  • 1
  • 5
  • 5

1 Answers1

3

Install procmail if not already installed. In your postfix configuration ( /etc/postfix/main.cf ) make sure you have a line:

mailbox_command = procmail -a "$EXTENSION"

in your ~/.procmailrc insert the following (you will need a different matching pattern):

:0
* ^Subject:.*some_text_to_match
| /usr/local/bin/your_processing_program

In your_processing_program extract the attachments and forward them e.g. with a python or ruby program.

How to display the attachments in terminal depends on the attachment content. If it is text you could write it to the end of a file and use tail -f in the terminal.

Anthon
  • 78,313
  • 42
  • 165
  • 222