title: Configure SPF, MX and Postfix for sending email from SMTP relay
body: <p>After searching for a while and reading a lot of examples, cases and/or answer on Google and Stackoverflow, I didn't find a solution for my problem. I'm more and more confused with the notion of SPF and relay, so I'm asking my question here hoping to receive a proper answer and understand once for ever !</p>
  
  <p>In summary :</p>
  
  <ul>
  <li>I have a current main server with a mailserver installed on it (postfix + dovecot + vimbadmin), on domain exampleA.com.</li>
  <li>I have a new server for a new website, with a new domain exampleB.com.</li>
  </ul>
  
  <p>My goal is that all the emails of the new website (XXXX[AT]exampleB.com) have to be sent &amp; received using the main server.</p>
  
  <p>Knowing that the mainserver has to send the emails of exampleB.com, I modified the SPF entry of exampleB.com to allow the main server to send emails of exampleB.com.</p>
  
  <p>The mails are sent OK and I receive the emails OK, but when I look the original sources of email in Gmail :</p>
  
  <pre><code>Return-Path: &lt;root@FQDN_NEW_SERVER&gt;
  Received: from mail.exampleA.com (FQDN_MAIN_SERVER [IP_MAIN_SERVER])
          by mx.google.com with ESMTPS id f64si6392532wma.52.2016.05.20.04.59.06
          for &lt;xxxxxxx@gmail.com&gt;
          (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
          Fri, 20 May 2016 04:59:06 -0700 (PDT)
  Received-SPF: neutral (google.com: IP_MAIN_SERVER is neither permitted nor denied by best guess record for domain of root@FQDN NEW SERVER) client-ip=IP MAIN SERVER;
  Authentication-Results: mx.google.com;
         spf=neutral (google.com: IP MAIN SERVER is neither permitted nor denied by best guess record for domain of root@FQDN NEW SERVER) smtp.mailfrom=root@IP MAIN SERVER
  Received: from FQDN NEW SERVER (REVERSEDNS_NEW_SERVER [IP_NEW_SERVER])
      by mail.exampleA.com (Postfix) with ESMTPA id 67C8C60421;
      Fri, 20 May 2016 13:59:06 +0200 (CEST)
  Received: by FQDN_NEW_SERVER (Postfix, from userid 0)
      id A1949A07AB; Fri, 20 May 2016 13:58:57 +0200 (CEST)
  </code></pre>
  
  <p>I'm getting more and more confused which SPF I have to modify, and which MX is pointing to who..</p>
  
  <p>Edit : It seems that I have a connection timed out when my main server tries to connect to my new server on port 25, but with telnet it seems ok..</p>
  
  <p>Edit2 : I know that my DNS and my Reverse DNS are not the same.. My server is an instance in a public cloud, and I can't change my reverse since it's configured in the virtual router. </p>
  
  <p>Edit3 : I have this error in the main server postfix logs :</p>
  
  <pre><code>May 20 16:25:40 ns33rgdrg4 postfix/smtpd[2956]: NOQUEUE: reject_warning: RCPT from csikxdqzdqzdqzdqzdqzress.com[IP_NEW_SERV]: 450 4.1.7 &lt;root@FQDN_NEW_SERVER&gt;: Sender address rejected: unverified address: connect to FQDN_NEW_SERV[IP_NEW_SERV]:25: Connection timed out; from=&lt;root@FQDN_NEW_SERV&gt; to=&lt;myownmail@owndomain.com&gt; proto=ESMTP helo=&lt;FQDN_NEW_SERV&gt;
  </code></pre>
  
  <p>Here is the current configuration of servers :</p>
  
  <h2>Server Main</h2>
  
  <pre><code>Dovecot + Postfix configured  
  Domain : exampleA.com  
  DNS :
  
   - exampleA.com.        MX    mail.exampleA.com
   - mail.exampleA.com    A     IP_MAIN_SERVER
   - exampleA.com.        SPF   "v=spf1 a mx ptr include:spf4.newsletterpartner.net ~all"
  </code></pre>
  
  <h2>New server</h2>
  
  <p>Postfix installed, normally why relayhost = mail.exampleA.com  </p>
  
  <pre><code>Domain : exampleB.com  
  DNS :
  
   - exampleB.com.        MX    mail.exampleA.com
   - exampleB.com.        SPF   "v=spf1 mx:mail.exampleA.com mx:exampleA.com include:mail.exampleA.com include:exampleA.com ~all"
  </code></pre>
  
  <p>The MX of my new domain is pointing to the MX of my main server (I don't know if it is the good thing to do)</p>
  
  <p>Here is the a part of the new server /etc/postfix/main.cf :</p>
  
  <pre><code>myhostname = FQDN_NEW_SERVER
  alias_maps = hash:/etc/aliases
  alias_database = hash:/etc/aliases
  myorigin = /etc/mailname
  mydestination =
  mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
  mailbox_command = procmail -a "$EXTENSION"
  mailbox_size_limit = 0
  recipient_delimiter = +
  
  relayhost = mail.exampleA.com
  smtp_sasl_auth_enable = yes
  smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
  smtp_sasl_security_options =
  </code></pre>
  
  <p>We can see that the new server has his postfix relayhost pointing to the MX of my mainserver.</p>
  
  <p>I don't know if the MX of my new server has to point to himself (knowing that its own postfix has a relayhost configured), or if it has to be configured directly to the main server which will send the emails.</p>
  
  <p>NB : I have this error : <code>No SPF records found for mail.exampleA.com</code> when I check with a website looking for MX and SPF, but exampleA.com has a MX, not mail.exampleA.com</p>
  
  <p>It's driving me crazy for days now... Thanks in advance for your little helps guys :)</p>
  
  <p>Regards,<br>
  Julien Q.</p>