0

My goal is to add emails to a DB and then send them on to the user at a different domain.

My mail server is hosted elsewhere using my domain, (me@example.com). TO get this working, I set up postfix on a server that gets mail for sub-domain, say, "process.example.com". I followed these instructions to get the PHP piping working.

I have set this up using a PHP script that parses the email, logs it, then re-builds the email and sends it on. My issue is that some messages do not look great after being parsed and reassembled. I realized I might be doing this the hard way. This needs to take an email from me@process.example.com, call my milter for processing, change the TO to me@example.com and send it on its way.

I have read about several postfix process like transport, relay and canonical. I am thinking I need to use one of these, but have not instructions. I also am not sure that my milter will be called if I use one of the processes like relay or canonical.

Can someone give me some help with my postfix config...

As requested, here is output for postconf -n

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
default_privs = apache
html_directory = no
inet_interfaces = all
inet_protocols = all
local_recipient_maps = 
luser_relay = catchall
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
milter_default_action = accept
milter_protocol = 2
mydestination = $myhostname, localhost.$mydomain, localhost, process.example.com
mynetworks = 168.100.189.0/28, 127.0.0.0/8
mynetworks_style = host
myorigin = $myhostname
newaliases_path = /usr/bin/newaliases.postfix
non_smtpd_milters = $smtpd_milters
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
sample_directory = /usr/share/doc/postfix-2.6.6/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtpd_milters = inet:127.0.0.1:8891
unknown_local_recipient_reject_code = 550
  • Wait, you are using PHP milter to parse email....? Very, very hardcore :) – masegaloeh Dec 18 '14 at 7:28
  • All my controller and views are already created there. It is also what I am most familiar with. You making fun of me? ;>) – Thom Jan 14 '15 at 22:49
  • No, it's not about PHP, it's about milter. I am not familiar with milter as it comes from sendmail. But you managed to write milter with PHP. How awesome is it :) – masegaloeh Jan 15 '15 at 0:15
1

Every email received by postfix always be passed to milter. So you shouldn't have worry about it.

To do rewriting, you can use recipient_canonical_maps here.

In main.cf add this parameter

recipient_canonical_maps  = hash:/etc/postfix/process2main

And in /etc/postfix/process2main add this line

me@process.example.com me@example.com

This will rewrite recipient from me@process.example.com to me@example.com

See this page to get how canonical works

  • I like the approach and am trying to test it. But I will now need another way to pipe my messages to my script. I was using catchall in /etc/aliases. If I take the approach above, how to I pipe all messages to my php script? I was using "catchall: |"php -q /home/web/www.example.com/public_html/index.php emailparse" – Thom Jan 14 '15 at 22:46
  • for clarification: did you replace milter with catchall pipe script? – masegaloeh Jan 15 '15 at 2:58
  • Showing my ignorance in this area, I had it set up as a catchall, but called it a milter. Now trying to make it a filter using this page. blog.thecodingmachine.com/content/… I have the canonical map working like you describe above, but cannot get it to run the script. I am trying to test this using sendmail -t -v on the same machine. I can see in maillog that it is invoking postfix, but nothing about the filter. – Thom Jan 15 '15 at 15:17
  • I am so close. Using the recipient_bcc as described in the link above, I am now able to send messages from the command line, the recipient_canonical alters the TO address and the script parses the message. BUT, when I send a message from my desktop to the server I see the message being processed in the maillot, the script does its thing, the maillot says it is relaying to my mail host (identical line in log to CLI), yet I never receive the email message. – Thom Jan 15 '15 at 22:23
  • This worked. Still having issues sending email from the box, but that seems like a new question. Thanks for your answer. – Thom Jan 16 '15 at 17:22

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.