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: test@manoj.com

Now, all the mails are being accepted by gmail server. But, now any mails send via my postfix server has from address "test@manoj.com".

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.

  • Which command/program/application/script did you use to send the email? – JayMcTee Oct 30 '15 at 12:54
  • We have different applications, the scripts are in python,bash etc..Its not not possible to change scripts.. – Manoj S T Oct 30 '15 at 13:14
  • 5
    The solution is to fix the misbehaving scripts. This is simple; all you need is a text editor. – Michael Hampton Oct 30 '15 at 14:20

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.

  • The mail has got "from" address. The issue is that, postfix is not adding the from field to mail headers.. I need a regexp to add it... – Manoj S T Oct 30 '15 at 14:39
  • Ok, so where is "from" address located in those emails? From: field is that part of email header, where this need to be located. Paste here source code of one of those emails (as they are generated from application) and we will see, but as far as I understand whole problem your emails haven't From: header with senders address and you're trying to fake those header on your mailserver instead of fix your apps to generate emails correctly. – Ondra Sniper Flidr Oct 30 '15 at 14:55
  • Yes, I need to add a header to it...I can do it..as I already stated in my previous update.. – Manoj S T Oct 30 '15 at 15:41
  • So if you need to add a header, your applications doesn't do that - just fix your applications to add From: header to generated emails and you're done. I don't believe in some dwarfs who delete From: header from emails between app and mailserver. – Ondra Sniper Flidr Oct 30 '15 at 17:37

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

  • Guys, I was able to get it working finally. – Manoj S T Nov 5 '15 at 12:11
  • Please do share how you did it, for others to learn from it. – JayMcTee Nov 5 '15 at 12:54
  • Guys, add the line "always_add_missing_headers = yes" to /etc/postfix/main.cf this will generate headers automatically. This needs to be done for versions from 2.6.6. At last got everything work perfectly !!!! – Manoj S T Nov 6 '15 at 5:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.