Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have an app on a server that sends mail via the local system's 'sendmail'. I want to write a program that takes the payload of the message, modifies it, and then sends it on to the original recipients.

I am running sendmail 8.14.4-8 on a Red Hat 6.4 server.

I thought that I could replace the link to /usr/sbin/sendmail with a link to my own script that would do the work and then delegate to the actual sendmail binary.

That didn't seem to work, so next I tried setting up a programmable SMTP server on the same host and tried to get sendmail to relay the messages to it, but sendmail didn't want to relay to any port other than 25. I tried using the following lines:

dnl define(`RELAY_MAILER_ARGS', `TCP $h 8025')dnl
dnl define(`ESMTP_MAILER_ARGS', `TCP $h 8025')dnl

My reading suggested that would work, but sendmail just kept trying port 25.

Anyone have any other ideas how I could approach this problem?

Thanks, Carl

share|improve this question
2  
Your first solution -- replacing the system sendmail with a wrapper script -- should have worked just fine. What do you mean by "that didn't seem to work"? –  larsks Jul 25 '13 at 21:14
1  
Have you thought about implementing a milter to do this? –  Mike B Jul 25 '13 at 22:41
    
@larsks - When I tested by echoing to the local mail program, I could see the shell script create a temp file, so I knew it worked. When I tried to have the real app send mail, I didn't see a temp file, but I saw the message get processed in /var/log/maillog. –  Carl Jul 25 '13 at 23:42
    
@Mike B - I am no sendmail expert-- I don't know anything about implementing a filter, but if you pointed me in the right direction, that would be great! –  Carl Jul 25 '13 at 23:43
    
It sounds as if your application isn't actually calling the sendmail binary. Possibly you have an smtp server listening on localhost and the program is talking to that directly. If that's the case, @MikeB's suggestion of using a milter is a reasonable idea, as is implementing some sort of filtering SMTP proxy server. There are lots of guides out there to both. –  larsks Jul 26 '13 at 1:10
show 1 more comment

1 Answer

Thanks to @MikeB's suggestion above. I thought 'milter' was a typo, but sendmail mail filters literally are called 'milters'. Go figure. Anyway, i wrote a milter that lets me modify the outgoing message and i must say it was not nearly as dificult as some of the other things I tried.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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