Our dev server is a CentOS LAMP system for developing web sites. We want PHP to send email. The server doesn't need to receive email or anything else, literally just send email to our developers.
I read about nullclients and how they can drop in instead of postfix, but I didn't fancy using something not in a repository. After a little fiddling I got postfix to (try) send email, by using settings similar to those found in the Postfix on a null client instructions on the Postfix Standard Configuration Readme:
myhostname = localhost.localdomain
myorigin = localdomain
relayhost = $mydomain
inet_interfaces = loopback-only
mydestination =
Once I set it up like this, I tried to send an email with telnet and saw the following error from /var/log/maillog
:
Apr 23 19:26:25 devserver postfix/smtp[34437]: 604E95209C3: to=<[email protected]>, relay=localdomain[82.147.22.3]:25, delay=0.54, delays=0.07/0/0.07/0.41, dsn=5.0.0, status=bounced (host localdomain[82.147.22.3] said: 550-Please turn on SMTP Authentication in your mail client, or login to the 550-IMAP/POP3 server before sending your message. ourstatic.hostname.isp.co.uk (localhost.localdomain) 550-[123.456.789.0]:54710 is not permitted to relay through this server 550 without authentication. (in reply to RCPT TO command))
So presumably our ISP will allow email being sent, but it must be authenticated. Does this mean with them or with the server we're trying to send email to? I've read about SASL with postfix but I'm not sure if that's the route I should go down.
Please provide suggestions or further reading, including whether you think there is a better alternative altogether. More information I've missed I'll be glad to share.
Update
In reply to some of the comments - I am not trying to relay through my ISP, but when I use postifx on the dev server to try send an email, the above is what I see, so presumably the ISP is blocking it.
Something I forgot to add, which confuses me further. We were previously using WampServer and had an install of hMailServer on our machines which was setup with SMTP only. Sending email via this (with Windows SMTP settings in php.ini) worked fine and we had no issues with this relay message. I have no idea why the difference now we're trying to use postfix. - I see that hMailServer acts as an SMTP server - which is exactly what I want to do with postfix.
As for having an internal mailserver in the company, we do have one in a different office but we don't want to route email elsewhere - we just want to have a way for the PHP to send email to just the devs without affecting production services if anything went wrong (like blacklisting or something).
Maybe my setup is wrong in that postfix/my ISP think I'm trying to use them as a relay, when all I want to do is have a simple SMTP functionality via postfix to send an email. Any further suggestions?
Unless you have set postfix up with a relayhost most likely thing here is that either you are sending to addresses on the same isp and their mailserver sees you as in their network and needing to be authenticated, or they capture all traffic on port 25 and redirect it to their own mail server (which is common but somewhat evil IMHO).
The solution to both cases is to set postfix to use your ISP mailserver as a relayhost with authentication. Such configuration is well documented in postfix's manual.
You are trying to set up a mail relay. The following config in
/etc/postfix/main.cf
should be enough:After changing the config, restart Postfix using
/etc/init.d/postfix restart
You need a fixed IP address if you want to reliably sent to the Internet. You will have much better success if you get the
PTR
record set to return the DNS name of you mail server. If you can't get a fixed IP address, use your Provider's relay server to send email.Typically if your domain is
example.com
then then you mail host would be configured assmtp.example.com
ormail.example.com
. This would be theMX
forexample.com
. Postfix should be setup to identify itself with this domain name, notlocalhost.localdomain
.localhost.localdomain
will not have an MX on the Internet and many servers will refuse email or file it as spam.You should consider setting up SPF (Sender Policy Framework) DNS records for your domain.
Alternative approaches: - You can configure the server to authenticate to your developer's
MX
and deliver over an authenticated connection.- You can get your host configured as a local server on the developer's
MX
server. This requires that you can identify the mail administrator for theMX
. They will likely require that you have a fixed IP address.I realised that my use-case was Postfix on a stand-alone Internet host:
I reset my
main.cf
to default, tried to send an email via PHP and tailed themaillog
giving me this error:This immediately made me think SELinux...
And now it works! A big lesson learned in a very roundabout way. Thanks for all the help!