Gmail not accepting emails from my local Postfix server

When I am trying to send from my postfix server to gmail accounts, I am getting the following error message in logs:

Our system has detected that this message is 550-5.7.1 not RFC 2822 compliant. To reduce the amount of spam sent to Gmail, 550-5.7.1 this message has been blocked. Please review 550 5.7.1 RFC 2822 specifications for more information. xt7si10601581pab.187 - gsmtp (in reply to end of DATA command))

After troubleshoot a lot, I found that this is because "from" address field is not present in email headers generated from my postfix server.

I enabled header check in "/etc/postfix/main.cf" using the line below:

header_checks = regexp:/etc/postfix/header_checks

and added following line to the file :

!/^From:/ REPLACE From: [email protected]

Now, all the mails are being accepted by gmail server. But, now any mails send via my postfix server has from address "[email protected]".

I need a regexp in postfix, which replaces the header with the "from" address to the same from address it has been sent.

In short, I want to generate a mail header with "from" field same as that of from address.

Please help.


Solution 1:

You're fixing it in wrong point. You should fix/change applications which sends emails without From: header, not faking it on your mailserver. Email without From: header is incorrect and should be blocked by first server on the path.

Solution 2:

I agree that it seems like you should in fact be looking at the scripts that make the sendmail/mail commands, as it is probably there where things are going wrong.

But, if you cannot alter those scripts, you can at least find out what they are streaming to whichever mail command is being used, and then you amend this stream on the fly, appending from headers etc.

See how I used sed to accomplish this elsewhere: https://stackoverflow.com/questions/15250199/crontab-email-through-msmtp-amazon-ses/32842451#32842451

Basically, assuming it's sendmail invoking the sending of mail, you rename the sendmail.bin and then create your own sendmail.bin which contains the sed based interception of the stream, its manipulation, and then forwards it to the renamed sendmail.bin