-1

I have a website in PHP sending multiple email to its users.

Because I need to be able to debug emails, I've created an email account (system@example.net) and, I've added this email address to the BCC field of every email my server send.
It's been very useful, but I've underestimated the number of email my server is sending and the inbox of this account is becoming very messy.
What I would like to do is, either through configuration or through scripting, automatically put emails into a specific folder based on their subject.

For example every email matching the regex below should be put inside a "Welcome" folder

/Welcome to my website ([A-Za-z0-9])\w+/g

How can I configure my server/Create a script to automatically organize an email account's inbox based on email subject ?

My website is using Apache2, php5.6, Postfix and dovecot.

M. Eriksson
  • 13,450
  • 4
  • 29
  • 40
Gary Olsson
  • 1,207
  • 22
  • 33
  • 2
    It's the mail client that moves the emails between folders. You can't control what folder the email you're sending are going to end up in on the receivers account. Check your email client (or perhaps your email server) for instructions on how to add filters. – M. Eriksson Aug 29 '17 at 13:01
  • @MagnusEriksson There is server-side `sieve` scripting facility (implemented as `pidgeonhole` for `dovecot`) that allow to sort out and move message to the desired IMAP folder without any interaction with MUA. User can set up `sieve` rules that move matching messages to the corresponding subfolders of the INBOX. – Kondybas Aug 29 '17 at 13:51

1 Answers1

1
  • dovecotshould be installed with pidgeonhole and managesieve support.
  • MTA (postfix) should be configured to use dovecot-lda instead of internal LDA.
  • Email-client like Thunderbird should be configured to be able create sieve rules on the server.
  • Proper subfolders should be created and subscribed within IMAP maildir.

If all prerequisites are fulfilled you can create the script like that:

require "fileinto";
if anyof (header :contains "Subject" "Welcome to my website")
{
   fileinto "Welcome";
   stop;
}
Kondybas
  • 686
  • 6
  • 15