Wednesday, January 26, 2011

How to send mail with hMailserver from different IPs for different domains?

domain abc.com should send from ip 1.1.1.1 and domain xyz.com should send from ip 2.2.2.2

I could not find how to configure the the IP for bothh domains differently. However I already found where to change the IP for all domains (under TCP/IP Ports).

  • That's not a decision hMailserver can easily make, as hMailserver relies on the TCP/IP stack in your system for the transport. Therefor the outgoing interface is decided by the routing decision your kernel makes. Typically you will have a routing table like this:

    IPv4 Route Table
    ===========================================================================
    Active Routes:
    Network Destination        Netmask          Gateway       Interface  Metric
              0.0.0.0          0.0.0.0     192.168.0.42     192.168.0.16    266
            127.0.0.0        255.0.0.0         On-link         127.0.0.1    306
            127.0.0.1  255.255.255.255         On-link         127.0.0.1    306
      127.255.255.255  255.255.255.255         On-link         127.0.0.1    306
          192.168.0.0    255.255.255.0         On-link      192.168.0.16    266
         192.168.0.16  255.255.255.255         On-link      192.168.0.16    266
        192.168.0.255  255.255.255.255         On-link      192.168.0.16    266
            224.0.0.0        240.0.0.0         On-link         127.0.0.1    306
            224.0.0.0        240.0.0.0         On-link      192.168.0.16    266
      255.255.255.255  255.255.255.255         On-link         127.0.0.1    306
      255.255.255.255  255.255.255.255         On-link      192.168.0.16    266
    ===========================================================================
    

    All traffic to the internet (0.0.0.0/0) at this system goes from Interface 192.168.0.16. Even if you add a second interface with the same gateway, netmask and metric the computer will just pick one of the two and always use that one. So there is no easy way to do what you want.

    usr : Our server has multiple internet-visible ips because it serves multiple websites btw.
    pehrs : Well, having multiple IP addresses lets you bind services to multiple addresses. The server will still pick one to bind to when you create an outgoing connection. If you have a look at a guide to socket programming such as http://www.amk.ca/python/howto/sockets/ you will see that you only define the destination address for a client socket.
    usr : This iy python-specific. As a .net programmer I know that you can bind the socket before listening to a port _and_ and ip if you want to (http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.bind(VS.90).aspx). EndPoint is a tuple of (ip, port).
    pehrs : @usr: You can always pick an IP when you open a socket to listen. But when you create a client socket to connect to another system you don't get to pick the local ip. Difference here is between server socket (or listening socket) and a client socket (or outgoing/connecting socket).
    From pehrs
  • It's not hMailserver which decides which IP address is the sender. That's determined by normal network routing. You will need to pass the outgoing mail for one of the domains to another MTA, which is configured to send that mail out on a particular IP address. As this can be a tricky issue on a single machine I suggest having the second MTA on a separate machine. A minimal virtual machine would do nicely for this.

    usr : The application can specifiy which ip to use when sending (it can of course also say: i dont care). So in theory hMailserver can decide this.
    John Gardeniers : I've just had a look at my hMailserver and can't find that setting. I can tell it what IP address to listen to and what address to rout outgoing mail to but not what IP address to use as the sender. Maybe I've overlooked it, so can you tell me where to set the originating address for a domain so I can test it?
    usr : Thanks for looking! Where can I find the setting where I can say the outgoing address? Thats exactly what I am looking for (hope I can set this per domain...).

0 comments:

Post a Comment