How to Configure Custom SMTP Routing


Xeams typically does an MX lookup for foreign domains when sending out emails. If the recipient is local, it skips the MX lookup and sends the message to the IP/host configured for the domain.

If you aim to send every outbound message through a single server, you could specify a Smart Host. Smart Host, however, has one limitation: you cannot specify exceptions. Consider the following scenario:

  • You want every outbound emails to go through your corporate office. That IP address is 20.30.40.50.
  • You want Xeams to perform an MX lookup, if the recipient belongs to @example1.com and @example2.com.

The scenario mentioned above cannot be implemented by Smart Host, since there is no way to force a handful of domains to perform an MX Lookup.

This page talks about an alternate method of specifying rules to route emails for certain sender/recipient through a specific server.

Steps

  • Connect to the machine where Xeams is running and open Windows File Explorer. If running on Linux, connect via SSH.
  • Go to the folder where Xeams is installed. Let's call this folder $INSTALL_DIR.
  • Go to $INSTALL_DIR\config
  • Create a new file called CustomSmtpRouting.xml
  • Here is a sample XML file.
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <CustomRouting>
    	<Routes>
    		<!-- Example 1. Send messages from sales@yourcompany.com 
    		to any recipient as long as the 
    		recipient does not belong to example1.com, example2.com or 
    		is auser@example3.com to
    		20.30.40.50
    		-->
    		<Route>
    			<!-- The sender's email address or domain name. Domain 
    			names MUST start with an @ symbol. 
    			This parameter can only have ONE sender.
    			
    			This is a mandatory field. It cannot be left blank.
    			-->
    			<sender>sales@yourcompany.com</sender>
    			
    			<!-- The recipient's email address or domain name. 
    				Domain names MUST start with an @ symbol. 
    				The word 'ANY' indicates any domain. This 
    				parameter can ONLY have one recipient.
    				 
    				This is a mandatory field. It cannot be left blank.
    			-->
    			<recipient>ANY</recipient>
    			
    			<!-- Pipe separated domain names or email addresses 
    			to exclude from this route. 
    			These exceptions ONLY apply when 'ANY' is used for the 'recipient
    			-->
    			<recipientExceptions>@example1.com|@example2.com|auser@example3.com</recipientExceptions>
    			
    			<!-- 
    			Subject is an optional node. If present, an IP is returned only if the email's subject matches with the 
    			given criteria.
    			
    			The operand must be one of the following values:
    			cn - Contains
    			sw - Start With
    			ew - Ends with
    			rg - Regular Expression
    			
    			If operand is missing or invalid, "cn" is assumed.
    			-->
    			<subject operand="cn">asap</subject>
    			
    			<!-- IP Address or host name of the server. Multiple IP 
    			addresses can be separated by a PIPE. 
    			A random IP address is returned when multiple addresses are found. 
    			
    			This is a mandatory field. It cannot be left blank.
    			-->
    			<ip>20.30.40.50</ip>
    		</Route>
    		<!-- Route 2 . Send emails from example4.com that are sent 
    			to any user in example3.com to 50.40.30.20
    		-->
    		<Route>
    			<sender>@example4.com</sender>
    			<recipient>@example3.com</recipient>
    			<recipientExceptions></recipientExceptions>
    			<ip>50.40.30.20</ip>
    		</Route>
    	</Routes>
    </CustomRouting>
    
  • This file contains two examples demonstrating how to create rules.
  • Save the file.

Important:

You should not use the methods specified on the SmartHost page if you decide to use this option.