save attachment to folder or nextcloud on incoming email

Discussion in 'General' started by CaptainBalou, Mar 18, 2021.

  1. CaptainBalou

    CaptainBalou Member

    Hello all,

    I am wondering if there is a possibility to realize the following scenario. I have a scanner which is capable of scan to email function. I would like to send the scan to a special email address managed by ISPconfig and then parse this email for attachments to automatically detach the PDF file to a local folder or even better to a nextcloud upload folder or a script.

    Can anyone assist in if this is possible and a hint how to do this?

    A quick summarization of the workflow:
    - Scan to email on scanner
    - Receive email and detach PDF attachments automatically
    - save to folder on server or handle it with a script

    Thanks in advance for any comments.


  2. Jesse Norell

    Jesse Norell ISPConfig Developer Staff Member ISPConfig Developer

    Two ways come to mind, create your email address ([email protected] or whatever) and then use either a postfix transport or a sieve filter to forward mail to your processing script. Using a postfix transport you would define the transport in /etc/postfix/ then use Email Routing to set your email address to use it (enter the email address as the Domain, Type 'custom', and your transport (eg. 'extract-pdf:') as Destination. Using a sieve filter you would need to enable the extprograms plugin to make your processing script available in a sieve filter, then just write a simple sieve script for this email address which does that.

    Either action (copying to a "folder" on the server being moving a file to a location, not move message to an imap folder - the latter is trivial via sieve) will require an external script to extract the attached file and do something with it.
    CaptainBalou likes this.
  3. CaptainBalou

    CaptainBalou Member

    Thanks a lot for this answer. Both ways absolutely new to me. Dont know how to do it exactly, but now I have something to search for. Thanks again.
  4. CaptainBalou

    CaptainBalou Member

    I thought the "transport option" could be worth a try. But a question again before doing this experiment. Can I add the new transport via ISPconfig gui or do I have to put it manually into the If I have to do it manually the upcoming question would be if this is then upgrade safe or do I have to repeatedly add it again after an upgrade?
  5. Jesse Norell

    Jesse Norell ISPConfig Developer Staff Member ISPConfig Developer

    You define the transport in manually, then set the email address to use it in the ui. It will be upgrade safe.
    CaptainBalou likes this.
  6. CaptainBalou

    CaptainBalou Member

    I did it that way and it works like a charm. Thanks again @Jesse Norell .
  7. cwtudor

    cwtudor New Member

    Is it possible to show an example of how you define the transport in /etc/postfix/ the the processing script used?
  8. CaptainBalou

    CaptainBalou Member

    My /etc/postfix/ is like this:

    extract-attachments   unix  -       n       n       -       -       pipe
        flags=X user=web22  size=26214400 argv=/scriptarchive/local/
    After this I used ISPConfig to define a transport for a specific email address to this transport extract-attachments.
  9. cwtudor

    cwtudor New Member

    Perfect, thanks so much.

Share This Page