Postfix sending problem - Gmail

Discussion in 'Server Operation' started by martini, Sep 10, 2007.

  1. martini

    martini New Member

    Hi,

    I am managing a server with Postfix installed. Due to the problems with spam I've moved all the email accounts onto GMail which is working fine.

    The only problem I have is email that is being sent from web forms (contact, appointments bookings etc) for domains that are hosted on my server. Postfix thinks that these emails accounts should be local as the domain is on the server.

    Can anyone help me configure it so that the email is sent out from the server to gmail?

    mydomain.com <- hosted on my server
    myname@mydomain.com <- email account which is managed by GMail
    mydomain.com/appointmentspage.php <- web page that tries to send email to myname@mydomain.com. This is actually hosted by GMail but postfix must thinks its actually local and tries to deliver it locally which fails.

    Many thanks in advance as i've read the postfix book but just can't seem to work this out.

    Cheers

    Dan
     
  2. chuckl

    chuckl New Member

    I may be completely wrong, but is this not just a matter of having DNS MX records with the right priority?

    e.g. if you have

    mail.myserver.com. MX 20
    smtp1.gmail.com. MX 10

    then smtp.gmail.com is where the mail will be forwarded by your server as it is the highest priority mail server, and therefore the ultimate destination for the mail.
     
  3. martini

    martini New Member

    Hi Chuckl,

    Thanks for the response.

    I'm a bit confused exactly how this would work. I have used Zoneedit to manage the DNS for the domains on my server. The MX records on there are set to the gmail settings and this works fine for all email which isn't on my server, if you get what I mean, e.g external email which is trying to get to the email boxes uses Zoneedit settings and therefore goes to GMail.

    I'm not able to update the DNS MX records on my server due to a limation of my ISP. I'm guessing that postfix then assumes that email that has a domain that is local should be delivered by the local process.

    Disclaimer - I'm only guessing here. I hope that it is a simple solution. I'm assuming that there is there is some setting in postfix which points email to hosts external even though the domain is local.... does this sound right or am I just babbling?

    Cheers

    Dan
     
  4. chuckl

    chuckl New Member

    If you're babbling, then so am I, so we're in excellent company. I solved the inverse problem to yours by the method I described. i.e. My domain registrar had 2 default mail servers et up for my domain, and once I had my server set up, I simply added an MX record there for my server with a lower priority number, and hence higher priority. All mail was then immediately forwarded on to my server.

    Your situation is slightly different I think, as you don't directly 'control' the MX records?
    Postfix has a config file relayhost parameter which specifies where non local mail is forwarded, but I think your problem is that it 'is' local mail to the system.

    Getting back to DNS entries, are you talking about the IspConfig machine, or a nameserver on the wider internet? You need to add MX entries on the mail server machine that gives a lower number/higher priority to the gmail servers.

    I suspect there is indeed some mechanism for setting this in the mail config, but I've never used it.

    Good luck, and hopfully someone else can give a definitive answer.
     
  5. chuckl

    chuckl New Member

    I've just remembered, 6 or 8 months ago I helped someone who was setting up an ecommerce site on his own server, and wanted to use Google Apps for the mail. We solved that by configuring Postfix to act as an MUA user agent rather than as a mail transport i.e. it would log on to Gmail as a user and send all mail through Gmail.
    Don't know if that might suit your needs?
     
  6. martini

    martini New Member

    Postfix acting like an MUA sounds like a possibility - was it tricky to do?

    As for the DNS MX, I think you're onto something here. I'm talking about the DNS MX record on a nameserver on the wider internet (zoneedit) - this means all incoming email sees the correct MX value and delivers email to GMAil.

    Do you know how I can tell which DNS my server uses? Its hosted by Fasthosts running Fedora 5 (I think). One other solution is to manually change the value of the DNS that the server is using - I assume I can do.

    Many thanks for your help
     
  7. chuckl

    chuckl New Member

    Yes, the Postfix MUA thing was fairly tricky, but mainly because of incomplete, misleading and wrong info. I think it is also called a nullclient setup, as the technique is to disable the local mail transport and direct all mail to an smtp transport to the desired mail host.
    In the case of Gmail, this is slightly complicated by the authentication etc. Note that this is not the same as a relay host.
    I still have the files stored, - main.cf, master.cf and the db files, but I'll have to dig for them. Not a problem if you're interested. In fact, now that I think about it, I have a testing VM setup that still has it installed, so easy to find.

    To summarise - it disables local delivery of mail and forces all mail to be sent via a specified transport to a remote mail machine.
    Incidentally, on the DNS score, doing the above work taught me the snippet that putting square brackets round the target machine name blocks DNS lookups by Postfix. e.g. smtp:[smtp.gmail.com]
    What this means is that Postfix will not attempt to establish whether this is a mail server for the recipient, it will simply send the mail.
     
  8. martini

    martini New Member

    Ah, I think we're definitely getting warmer. I want to disable my Postfix from using the local delivery method, lmtp, and use smtp instead.

    I think when Postfix recognises a local domain it doesn't bother to look up the MX record. I checked on my server with nslookup to see the MX records for my domain and it was correctly pointing to gmail.

    >nslookup
    >set type =MX
    >mydomain.com

    Non-authoritative answer:
    mydomain.com mail exchanger = 20 ASPMX3.GOOGLEMAIL.com.
    mydomain.com mail exchanger = 10 ALT1.ASPMX.L.GOOGLE.com.
    .....

    Authoritative answers can be found from:
    ALT1.ASPMX.L.GOOGLE.com internet address = 64.233.167.27
    ALT2.ASPMX.L.GOOGLE.com internet address = 66.249.83.114
    .....

    So I guess disabling my postfix lmtp and forcing it to use smtp would do the trick. btw I can send email successfully from my server to external addresses.

    If you do have any examples etc that would much appreciated

    Cheers

    Dan
     
  9. chuckl

    chuckl New Member

  10. chuckl

    chuckl New Member

    Right, sample files attached. I seem to remember we didn't disable the local transport, might not be necessary. If it is, a Google search for postfix nullclient will turn up a Postfix config page with some examples.
    Some recollections -
    The certificates are very necessary, won't work without them. Interestingly enough, it doesn't seem to matter what they say, as long as the names match the Postfix EHLO HELO signon server name.
    The advice in the article about adding the Gmail cert info is good, do it.
    Most common error is forgetting to run Postmap when you change the transport etc files.
    I think Gmail has emails/hr limits in force, watch the 50000 subscriber newsletter mailings.
    Shout if there are any queries/gotchas etc.
     

    Attached Files:

  11. martini

    martini New Member

    so close i can almost taste it...

    Thanks for the info Chuckl. i think i want something along the lines of a null client but don't want to go the whole hog and use gmail as my relay as I'm trying to keep it as simple as possible.

    I think i only need to change the config for the myuser@mydomain.com to use smtp not local. The rest of the config is fine e.g i still use my smtp for out going email.

    I'm beginning to get a feel for whats going on but still don't have the absolute answer.

    btw you definitely weren't babbling
     
  12. martini

    martini New Member

    so close i can almost taste it...

    Thanks for the info Chuckl. i think i want something along the lines of a null client but don't want to go the whole hog and use gmail as my relay as I'm trying to keep it as simple as possible and want to avoid the certs, limitation etc that gmail imposes.

    I think i only need to change the config for the myuser@mydomain.com to use smtp not local. The rest of the config is fine e.g i still use my smtp for out going email.

    I'm beginning to get a feel for whats going on but still don't have the absolute answer.

    btw you definitely weren't babbling
     
  13. martini

    martini New Member

    Job Done!

    Hi,

    Just thought I'd let you know that it now works.

    I just changed the transport for the mydomain.com in the etc/postfix/transport file. So for the domain that I want to send email to an email box managed by gmail I changed it to smtp. This forces smtp to then use the DNS to look up the MX value. (I think - please correct me if this is not the case).

    in /etc/postfix/transport
    ..
    mydomain1.com maildrop:
    mydomain.com smtp:
    mydomain2.com maildrop:
    ...

    then did

    >postmap transport
    then
    >postfix reload

    Hey presto! When my web form page tries to send email to myuser@mydomain.com postfix is forced to use smtp which then delivers it to the gmail server as the MX record has the gmail server values.

    So I think I have what is called a null client. My server accepts no email from the network. All email generated from my server, this only comes from web forms from websites i manage, gets sent out via smtp.

    Thanks for all your help Chuckl it lead me to find this solution.

    cheers

    Dan
     
  14. chuckl

    chuckl New Member

    I'm glad it's fixed, and that I was able to help. I was actually going to add a sooment to the effect that 'the answer lies in the transport file', but from your previous comments it was pretty apparent that you'd worked that out yourself.

    Rgds,

    Chuck
     

Share This Page