Forward root email to other email via postfix relay, strange problem

General support questions
Post Reply
plaguebreath
Posts: 3
Joined: 2017/06/13 16:54:44

Forward root email to other email via postfix relay, strange problem

Post by plaguebreath » 2017/06/13 17:17:39

First of all sorry for my english and thank you for help me in my difficult journey to learn Linux and by this using CentOs on an old HP ML110 I had chance to put hands on. Basically I fresh installed Centos 7 on a software raid 1 and that's the happy part of it. After that my next step was to get email from mdadm after some incident happen to my raid for doing that I set up Postfix (sendonly) only for relay my emails to my web provider SMTP server. And that's worked too after I testing with the:
echo "This is the body of the email" | mail -s "This is the subject line" gggg@xxxx.com
I got email correctly but from my user called root@domain.local
Now I would like to try to forward email sent from mdadm to root (or any mail sent from services to it) to my external address gggg@xxxx.com from an email like noreply@xxxx.com so first I try with for ~/forward and with Alias but at the end for change the FROM part I follow the suggestion here
https://serverfault.com/a/674984
but now the strage part of it is that if I test with mdadm email I get as result an email with FROM and TO uqual to noreply@xxxx.com but email is correctly delivered to my email address gggg@xxxx.com so what can I do for try to fix it ?
Every mail sent only to root has same TO address. Thank you for the help I really enjoy learning.

poky
Posts: 108
Joined: 2013/03/27 12:18:03

Re: Forward root email to other email via postfix relay, strange problem

Post by poky » 2017/06/19 20:09:54

Try insert line to /root/.mailrc:
set from=noreply@xxxx.com

plaguebreath
Posts: 3
Joined: 2017/06/13 16:54:44

Re: Forward root email to other email via postfix relay, strange problem

Post by plaguebreath » 2017/06/20 10:33:58

I try your solution, then I did a test on mdadm
mdadm --monitor --scan --test --oneshot /dev/md[[:digit:]]*
the results is email like :

FROM: centos1@mydomain.it
TO: root@centos1.localdomain

while my address is myaddress@mydomain.it

my /root/.forward is set with myaddress@mydomain.it
for setting the sender from my centos server I use this setting on postfix
change in /etc/postfix/main.cf

Code: Select all

sender_canonical_classes = envelope_sender, header_sender
sender_canonical_maps =  regexp:/etc/postfix/sender_canonical_maps
smtp_header_checks = regexp:/etc/postfix/header_check
I edit the file /etc/postfix/sender_canonical_maps

Code: Select all

/.+/    centos1@mydomain.it
I edit the file /etc/postfix/header_check

Code: Select all

/From:.*/ REPLACE From: centos1@mydomain.it
Still not working

plaguebreath
Posts: 3
Joined: 2017/06/13 16:54:44

Re: Forward root email to other email via postfix relay, strange problem

Post by plaguebreath » 2017/06/21 12:15:15

Ok seems I got it working, tell me if I did wrong please
I add to /etc/postfix/header_check

Code: Select all

/^To: root*/ REPLACE to: myaddress@mydomain.it
and now the header of the email that being forwarded from user root being correcty edited on header with the forward address.
Not very stylish but at least working :)
What you think about it ?

Post Reply