I am trying to add a custom header to all messages handled by my postfix server.
I tried using a guide on the internet without any luck.

In my master.cf i added:

> 
> -o smtp\_header\_checks=regexp:/etc/postfix/test\_tag\_header
> 
> 
> test\_tag\_header: Prepend X-Mailgun-Tag: testing123
> 
> 
> 

made sure I restarted postfix

I did a few tests to yahoo mail which has a full headers option.
The headers i added did not show up.

My goal is to add a custom header with a random value so that I can later parse the message using mailgun.org's api.

X-Mailgun-Tag: randomvalue (similar to url shortener)

---

**Based upon the answer from ank this is what i have so far:**
main.cf

> 
> smtp\_recipient\_restrictions = check\_recipient\_access
>  proxy:mysql:/etc/postfix/mailgun\_header.mysql
> 
> 
> 

mailgun\_header.mysql 

```
user        = vmail
password    = mypass
hosts       = 127.0.0.1
port        = 3306
dbname      = vmail
query       = select CONCAT(prefix, MD5(RAND())) as 'check_recipient_access' from mailgun_tokens where prefixID = 1;

```

when i try to restart postfix i get thef ollowing errors:

> 
> /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter:
>  smtp\_recipient\_restrictions=check\_recipient\_access
>  proxy:mysql:/etc/postfix/mailgun\_header.mysql
> 
> 
> 

\*

The sql query works fine through MYSQL and returns a row with a random number.