Monday, August 8, 2016

postfix - Can send mail but never receive the "Failed permanently" emails



I'm trying to build a system that analyzes incoming emails and automatically removes emails that fail permanently. But I never receive those emails that you usually receive when you send an email to an address that is not valid.



To test my system I use the command



mail -s "test mail" validemail@free.fr



I receive the email on my mailbox validemail@free.fr from root@myserverdomain.com



I reply to root@lyserverdomain.com to say hello, and I receive the email on myserverdomain.com.



Then I try this :



mail -s "test mail" invalidemaillllllllllllllllllllllllllllllllllllll@free.fr



And I never receive this email that tells you it's not a valid address.



If I'm sending an email from a "classic" email client (gmail for example) to invalidemaillllllllllllllllllllllllllllllllllllll@free.fr, I receive almost immediately this email telling me it's not a valid address.



So am I missing something? I think yes.



I'm using Postfix latest version on debian. It's configured on port 6666 (not 25 actually).
I'm using another smtp server on the same machine on port 25, it's a python script that receives external emails and analyzes them.


Answer




OK, I got it working.



Here is the explanation of what was happening :




  • When I send an email with postfix, postfix contact the smtp server of the domain in the receiver's email address.

  • The SMTP server replies that this account is not valid.

  • Postfix prepares an error email to send to the "return-path" field of the email, root@myserver.com

  • Postfix consider this is a local email address so he uses its own SMTP server to send this email. The python SMTP server that I've built to receive emails on this server is bypassed, and I never see this error email in my python script.




To solve this I've added an alias in Postfix configuration :
(debian)



vi /etc/aliases


Add this new alias in the file



root: newsletter@myserver.com



And then patch the alias data and relaunch python



newaliases
postfix reload

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...