0

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?

7
  • 2
    It looks like you're trying to relay through your ISP's SMTP server? Is that the case? If so, why not just send directly via DNS MX lookups?
    – joeqwerty
    Apr 23, 2014 at 19:34
  • The server doesn't need to receive email or anything else, literally just send email to our developers Why is the server sending emails to your developers through your ISP? Isn't there an internal mailserver for your company that this dev server could send the emails to instead? Apr 23, 2014 at 19:37
  • joeqwerty and HopelessN00b I have provided further information in an update - I do hope it helps clear up what I'm trying to do Apr 23, 2014 at 19:57
  • 1
    @LeonardChallis Ultimately it sounds like you're going to have to pick up the phone and call your ISP to find out why they're rejecting your mail. Presuming you're in a netblock that's supposed to be able to send outbound mail on port 25 they shouldn't be trying to request SMTP AUTH from you... (I think your configuration is fine - unless you're in a dynamic/no-outbound-SMTP IP block - and this is an issue with your provider)
    – voretaq7
    Apr 23, 2014 at 21:00
  • 1
    this question can NOT be answered until you verify that your isp is not doing any thing funny with traffic. It is entirely possible that they have set up some "spammer catchers" and you are being caught as a false positive. Many isp's require that any "server" activity be done through a business class account and block all residential traffic. Please verify tos from the isp and any filtering/blocking/redirecting they do. also sending email to the dev's is that to their work email or a personal email? what server is the mail going to?
    – Kendrick
    Apr 24, 2014 at 0:53

4 Answers 4

2

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.

1

You are trying to set up a mail relay. The following config in /etc/postfix/main.cf should be enough:

smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no
append_dot_mydomain = no

# Replace this with your mail server's hostname
myhostname = svc1.int.mtak.nl

alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases

# Replace this with your mail server's hostname
myorigin = smtp1.int.mtak.nl

# Domains for which local delivery is required, in your case only localhost
mydestination = smtp1.int.mtak.nl, svc1.int.mtak.nl, localhost.int.mtak.nl, localhost

# Host to which to relay mail to. Usually your ISP's SMTP server or your company's SMTP server, contact your administrator for details
relayhost = dc2.int.mtak.nl
# Networks that are allowed to send mail through your mail relay.
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 10.100.0.0/24 10.100.2.0/24 10.100.4.0/24

After changing the config, restart Postfix using /etc/init.d/postfix restart

3
  • Are you telling me I should set one up or that that's what I'm trying to do? I don't (think) I want a relay... I just want to send email... Apr 23, 2014 at 19:58
  • You are trying to set up a relay. Mail will get sent to the mail server process (postfix) on the dev server, which is a mail server in itself. The mail server will then have to forward the mail to your ISP's mail server where it can be delivered to the rest of the internet. If you just want the local host to send mail through this relay, use mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
    – mtak
    Apr 23, 2014 at 20:00
  • I tried that and it doesn't work unfortunately. So if I just want to set up postfix to send email without using another relay, with the above and my settings in my question can you see any reason it shouldn't work? Apr 23, 2014 at 20:35
1

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 as smtp.example.com or mail.example.com. This would be the MX for example.com. Postfix should be setup to identify itself with this domain name, not localhost.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 the MX. They will likely require that you have a fixed IP address.

2
  • We do have a fixed IP address actaully - I was hoping there wouldn't be a big need for setting up things like MX and SPF (which I don't know much about) if I literally just want to send some emails. If hMailServer on Windows can do it, I thought I'd be able to do a similar thing on CentOS? Apr 24, 2014 at 6:57
  • @LeonardChallis CentOS can, but because there are so many Spambots, most servers are tightening up their configurations. Just use your provider's relay and you should be good to go. It is best to use a proper domain name in configuring your server, but the relay should accept an illegitimate one.
    – BillThor
    Apr 25, 2014 at 1:16
1

I realised that my use-case was Postfix on a stand-alone Internet host:

Postfix should work out of the box without change on a stand-alone machine that has direct Internet access.

I reset my main.cf to default, tried to send an email via PHP and tailed the maillog giving me this error:

postfix/sendmail[1787]: fatal: chdir /var/spool/postfix: Permission denied

This immediately made me think SELinux...

sudo setsebool -P httpd_can_sendmail 1

And now it works! A big lesson learned in a very roundabout way. Thanks for all the help!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .