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 on one server domain1.com domain2.com domain3.com on CentOS and Qmail. I want them to send email trough a second server that uses ip1, ip2, ip3. I can easy do this by editing this Qmail file:

/var/qmail/control/smtproutes

and I add the IPs there, but I have no idea how I could set it to so that each domain sends trough its own IP. Is there a syntax in smtproutes file? e.g [if @domain1.com then use this IP]. OR Is there a way to redirect this on the second server by some mail filtering or firewall? So that a mail that comes from domain1.com will be send from ip1.com, domain2.com from ip2, etc.

Second server has Sendmail and I see it has some advanced features, I am not sure what to use, most of the relay options seem to help to redirect depending on receiver domain rather than sender domain (what I need).

// I am using the second server because main server has some filtering from provider anyway, but even when sending directly from main server, you cannot seem to be able to specify what IP to use when sending mail, qmail just uses default server IP in that case.

share|improve this question
    
The second server can and is set to listen on different ports and ips if needed. –  adrianTNT Sep 30 '11 at 19:49
1  
Why would you want to do this? Seems awfully complicated and failure prone. –  Chris S Sep 30 '11 at 20:02
    
main server host (Godaddy) would not allow me to directly send email unless using their own relay in smtproutes files, their IPs are often blacklisted. I want to sent trough outside servers and also set proper reverse dns for each IP. –  adrianTNT Sep 30 '11 at 20:20
    
The reverse DNS just has to match whatever the server declares itself to be in the EHLO. It doesn't have to match the MAIL FROM domain. SPF and DKIM both have mechanisms for these sorts of setups as well. It's pretty common. –  Chris S Sep 30 '11 at 21:41
    
@ChrisS ... as already stated in his other question's answers ... –  mailq Sep 30 '11 at 22:01

1 Answer 1

Well, you can use the qmail virtualdomain IP address patch to switch the IPs in your qmail.

You can achieve this in sendmail as well. Using the "DaemonPortOptions" in sendmail (with Modifiers=bh ) you can bind the sendmail daemon to multiple interfaces and the modifiers setting will force sendmail to use the same interface to send mail through which it received the mail.

Now all you need to do is to relay the mails based on sender to the corresponding IPs, for which you may need to rely on any patches available for qmail or any wrapper script like the one below,

#!/bin/sh 
configfile=/var/qmail/control/senderroutes 
host="$1" 
sender="$2" 
shift 2 
if grep -q "^$sender:" $configfile ; then 
host=`awk -F: "/^$sender:/{print \$2}" $configfile` 
fi 
exec /var/qmail/bin/qmail-remote.orig "$host" "$sender" "$@" 

Source: http://www.gossamer-threads.com/lists/qmail/users/136118

References:

http://www.digitaldaemon.com/FreeBSD/qmail/index.html

http://www.sendmail.org/~gshapiro/8.10.Training/DaemonPortOptions.html

share|improve this answer
    
From what I read, the domains before the ":" inside smtproutes file is the destination* domain, e.g gmail.com yahoo.com and are used to reach different providers using different routes. If I would be able to configure the "from" domain there then it would solve my problem. –  adrianTNT Sep 30 '11 at 22:38
    
Unfortunately Yeah..confused with the same format of cpanel mailips setup :(. Updated the reply with more sources which may give you some lead. Just trying to help :) –  SparX Sep 30 '11 at 23:40

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.