Postfix rewriting subject for specific addresses












3















I would like to add a tag to all email messages sent to a particular address. I have tried to copy examples from the web, but can't seem to get it working.



Here's what I've done so far:





  1. Add to /etc/postfix/transport



    email@example.com         rewrite:



  2. Add to /etc/postfix/master.cf



    rewrite    unix  -       -       n       -       -       smtp
    -o header_checks=pcre:/etc/postfix/rewrite_headers



  3. Create /etc/postfix/rewrite_headers containing



    /^Subject: (.+)$/i    REPLACE Subject: [Example tag] $1



If anyone can see where I am going wrong, please advise.



Thanks,



James










share|improve this question



























    3















    I would like to add a tag to all email messages sent to a particular address. I have tried to copy examples from the web, but can't seem to get it working.



    Here's what I've done so far:





    1. Add to /etc/postfix/transport



      email@example.com         rewrite:



    2. Add to /etc/postfix/master.cf



      rewrite    unix  -       -       n       -       -       smtp
      -o header_checks=pcre:/etc/postfix/rewrite_headers



    3. Create /etc/postfix/rewrite_headers containing



      /^Subject: (.+)$/i    REPLACE Subject: [Example tag] $1



    If anyone can see where I am going wrong, please advise.



    Thanks,



    James










    share|improve this question

























      3












      3








      3


      1






      I would like to add a tag to all email messages sent to a particular address. I have tried to copy examples from the web, but can't seem to get it working.



      Here's what I've done so far:





      1. Add to /etc/postfix/transport



        email@example.com         rewrite:



      2. Add to /etc/postfix/master.cf



        rewrite    unix  -       -       n       -       -       smtp
        -o header_checks=pcre:/etc/postfix/rewrite_headers



      3. Create /etc/postfix/rewrite_headers containing



        /^Subject: (.+)$/i    REPLACE Subject: [Example tag] $1



      If anyone can see where I am going wrong, please advise.



      Thanks,



      James










      share|improve this question














      I would like to add a tag to all email messages sent to a particular address. I have tried to copy examples from the web, but can't seem to get it working.



      Here's what I've done so far:





      1. Add to /etc/postfix/transport



        email@example.com         rewrite:



      2. Add to /etc/postfix/master.cf



        rewrite    unix  -       -       n       -       -       smtp
        -o header_checks=pcre:/etc/postfix/rewrite_headers



      3. Create /etc/postfix/rewrite_headers containing



        /^Subject: (.+)$/i    REPLACE Subject: [Example tag] $1



      If anyone can see where I am going wrong, please advise.



      Thanks,



      James







      email postfix






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 29 '15 at 17:52









      James ShieldsJames Shields

      14616




      14616






















          2 Answers
          2






          active

          oldest

          votes


















          1














          You should be able to do this without a custom transport, using built-in header checks.



          Add to main.cf:



          header_checks = pcre:/etc/postfix/rewrite_headers


          Your rewrite_headers file will have the existing rule wrapped in a conditional:



          if /^To: email@example.com$/i
          /^Subject: (.+)$/i REPLACE Subject: [Example tag] $1
          endif


          This should handle everything without the need for a transport config.






          share|improve this answer


























          • Is this also going to work if I want to change the sender of the mail for specific recipients?

            – wie5Ooma
            Jan 19 '18 at 22:46











          • Thanks for the tips. Unfortunately for me, my postfix config doesn't work as per documentation. header_checks doc says the header is checked in one bunch, not line by line. But this doesn't work accordingly to my config. So your tip doesn't work on my config.

            – Luc-Olivier
            May 25 '18 at 14:54











          • There was a mistake in my config example. header_checks was set to a file path, but as it contains regex rules the path needs to be prefixed with pcre:

            – Murphy's Prophet
            Jun 9 '18 at 2:37



















          0














          Unfortunately, the example above will not work as Postfix only works on one line at a time. The best I can tell, you will need a transport config.






          share|improve this answer








          New contributor




          Smuggler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





















          • This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

            – Michael Homer
            2 hours ago











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "106"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f252193%2fpostfix-rewriting-subject-for-specific-addresses%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You should be able to do this without a custom transport, using built-in header checks.



          Add to main.cf:



          header_checks = pcre:/etc/postfix/rewrite_headers


          Your rewrite_headers file will have the existing rule wrapped in a conditional:



          if /^To: email@example.com$/i
          /^Subject: (.+)$/i REPLACE Subject: [Example tag] $1
          endif


          This should handle everything without the need for a transport config.






          share|improve this answer


























          • Is this also going to work if I want to change the sender of the mail for specific recipients?

            – wie5Ooma
            Jan 19 '18 at 22:46











          • Thanks for the tips. Unfortunately for me, my postfix config doesn't work as per documentation. header_checks doc says the header is checked in one bunch, not line by line. But this doesn't work accordingly to my config. So your tip doesn't work on my config.

            – Luc-Olivier
            May 25 '18 at 14:54











          • There was a mistake in my config example. header_checks was set to a file path, but as it contains regex rules the path needs to be prefixed with pcre:

            – Murphy's Prophet
            Jun 9 '18 at 2:37
















          1














          You should be able to do this without a custom transport, using built-in header checks.



          Add to main.cf:



          header_checks = pcre:/etc/postfix/rewrite_headers


          Your rewrite_headers file will have the existing rule wrapped in a conditional:



          if /^To: email@example.com$/i
          /^Subject: (.+)$/i REPLACE Subject: [Example tag] $1
          endif


          This should handle everything without the need for a transport config.






          share|improve this answer


























          • Is this also going to work if I want to change the sender of the mail for specific recipients?

            – wie5Ooma
            Jan 19 '18 at 22:46











          • Thanks for the tips. Unfortunately for me, my postfix config doesn't work as per documentation. header_checks doc says the header is checked in one bunch, not line by line. But this doesn't work accordingly to my config. So your tip doesn't work on my config.

            – Luc-Olivier
            May 25 '18 at 14:54











          • There was a mistake in my config example. header_checks was set to a file path, but as it contains regex rules the path needs to be prefixed with pcre:

            – Murphy's Prophet
            Jun 9 '18 at 2:37














          1












          1








          1







          You should be able to do this without a custom transport, using built-in header checks.



          Add to main.cf:



          header_checks = pcre:/etc/postfix/rewrite_headers


          Your rewrite_headers file will have the existing rule wrapped in a conditional:



          if /^To: email@example.com$/i
          /^Subject: (.+)$/i REPLACE Subject: [Example tag] $1
          endif


          This should handle everything without the need for a transport config.






          share|improve this answer















          You should be able to do this without a custom transport, using built-in header checks.



          Add to main.cf:



          header_checks = pcre:/etc/postfix/rewrite_headers


          Your rewrite_headers file will have the existing rule wrapped in a conditional:



          if /^To: email@example.com$/i
          /^Subject: (.+)$/i REPLACE Subject: [Example tag] $1
          endif


          This should handle everything without the need for a transport config.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jun 9 '18 at 2:36

























          answered Jan 19 '18 at 22:14









          Murphy's ProphetMurphy's Prophet

          112




          112













          • Is this also going to work if I want to change the sender of the mail for specific recipients?

            – wie5Ooma
            Jan 19 '18 at 22:46











          • Thanks for the tips. Unfortunately for me, my postfix config doesn't work as per documentation. header_checks doc says the header is checked in one bunch, not line by line. But this doesn't work accordingly to my config. So your tip doesn't work on my config.

            – Luc-Olivier
            May 25 '18 at 14:54











          • There was a mistake in my config example. header_checks was set to a file path, but as it contains regex rules the path needs to be prefixed with pcre:

            – Murphy's Prophet
            Jun 9 '18 at 2:37



















          • Is this also going to work if I want to change the sender of the mail for specific recipients?

            – wie5Ooma
            Jan 19 '18 at 22:46











          • Thanks for the tips. Unfortunately for me, my postfix config doesn't work as per documentation. header_checks doc says the header is checked in one bunch, not line by line. But this doesn't work accordingly to my config. So your tip doesn't work on my config.

            – Luc-Olivier
            May 25 '18 at 14:54











          • There was a mistake in my config example. header_checks was set to a file path, but as it contains regex rules the path needs to be prefixed with pcre:

            – Murphy's Prophet
            Jun 9 '18 at 2:37

















          Is this also going to work if I want to change the sender of the mail for specific recipients?

          – wie5Ooma
          Jan 19 '18 at 22:46





          Is this also going to work if I want to change the sender of the mail for specific recipients?

          – wie5Ooma
          Jan 19 '18 at 22:46













          Thanks for the tips. Unfortunately for me, my postfix config doesn't work as per documentation. header_checks doc says the header is checked in one bunch, not line by line. But this doesn't work accordingly to my config. So your tip doesn't work on my config.

          – Luc-Olivier
          May 25 '18 at 14:54





          Thanks for the tips. Unfortunately for me, my postfix config doesn't work as per documentation. header_checks doc says the header is checked in one bunch, not line by line. But this doesn't work accordingly to my config. So your tip doesn't work on my config.

          – Luc-Olivier
          May 25 '18 at 14:54













          There was a mistake in my config example. header_checks was set to a file path, but as it contains regex rules the path needs to be prefixed with pcre:

          – Murphy's Prophet
          Jun 9 '18 at 2:37





          There was a mistake in my config example. header_checks was set to a file path, but as it contains regex rules the path needs to be prefixed with pcre:

          – Murphy's Prophet
          Jun 9 '18 at 2:37













          0














          Unfortunately, the example above will not work as Postfix only works on one line at a time. The best I can tell, you will need a transport config.






          share|improve this answer








          New contributor




          Smuggler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





















          • This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

            – Michael Homer
            2 hours ago
















          0














          Unfortunately, the example above will not work as Postfix only works on one line at a time. The best I can tell, you will need a transport config.






          share|improve this answer








          New contributor




          Smuggler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





















          • This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

            – Michael Homer
            2 hours ago














          0












          0








          0







          Unfortunately, the example above will not work as Postfix only works on one line at a time. The best I can tell, you will need a transport config.






          share|improve this answer








          New contributor




          Smuggler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.










          Unfortunately, the example above will not work as Postfix only works on one line at a time. The best I can tell, you will need a transport config.







          share|improve this answer








          New contributor




          Smuggler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          share|improve this answer



          share|improve this answer






          New contributor




          Smuggler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          answered 3 hours ago









          SmugglerSmuggler

          1




          1




          New contributor




          Smuggler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          New contributor





          Smuggler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          Smuggler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.













          • This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

            – Michael Homer
            2 hours ago



















          • This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

            – Michael Homer
            2 hours ago

















          This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

          – Michael Homer
          2 hours ago





          This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

          – Michael Homer
          2 hours ago


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f252193%2fpostfix-rewriting-subject-for-specific-addresses%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Loup dans la culture

          How to solve the problem of ntp “Unable to contact time server” from KDE?

          ASUS Zenbook UX433/UX333 — Configure Touchpad-embedded numpad on Linux