Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to get a python script to send mail (using smtplib.SMTP), but postfix is refusing to relay the message. I don't use the Ubuntu 10.10 Virtualmin server as a mail server (I happen to use google apps for that), but I want scripts to be able to send mail. Here is the log, with the addresses replsced with generic ones:

Apr 11 00:50:27 unimatrix-01 postfix/smtpd[25212]: connect from localhost[]
Apr 11 00:50:27 unimatrix-01 postfix/smtpd[25212]: NOQUEUE: reject: RCPT from localhost[]: 554 5.7.1 <>: Relay access denied; from=<> to=<> proto=ESMTP helo=<>
Apr 11 00:50:27 unimatrix-01 postfix/smtpd[25212]: lost connection after RSET from localhost[]
Apr 11 00:50:27 unimatrix-01 postfix/smtpd[25212]: disconnect from localhost[]

I have already tried with no success, to fix this by running # dpkg-reconfigure postfix according to the Ubuntu Docs. How can I fix this?

Thanks in advance.

Update: Interestingly, apps using PHP can send mail just fine. So, I suspect it has something to do with postfix requireing authentication locally. This is not necessary as I am use sole user of this VP. I hope this helps with troubleshooting.

share|improve this question
up vote 3 down vote accepted

Check if you permit local networks to relay emails without authentication.

First of all, the following command, should include permit_mynetworks

sudo postconf smtpd_recipient_restrictions

Then check if is in $mynetworks. Just do,

sudo postconf mynetworks

and check if is there.

share|improve this answer
Success! Thanks! – Sean W. Apr 11 '11 at 13:18
Works for mee too added smtpd_recipient_restrictions = permit_mynetworks to /etc/postfix/ and now python smtplib works to relay mail sent to localhost on to a given a relayhost. – here Feb 24 '14 at 0:37
+1 @here, thanks for that. It saved me a frustrating evening! – Karthic Raghupathi Nov 12 '14 at 22:11

I'm guessing you aren't setting mydomain anywhere, and thus are not telling postfix where it can deliver mail.

You essentially need to set mydomain = and then add or $mydomain to mydestination.

Make sure to reload/restart postfix

share|improve this answer
PHP apps can setil send mail via mail(). Would your guess affect that as well? – Sean W. Apr 11 '11 at 2:32
Honestly I'm not sure, I know I've seen this exact relay error before and this was the problem. Are you positive PHP is using postfix to send out? I would say try making the changes and see if this fixes it, but that my first recommendation. – rfelsburg Apr 11 '11 at 2:34
I tried as you suggested, and now postfix thinks that it's hosting the mailboxes for Recipient address rejected: User unknown in local recipient table – Sean W. Apr 11 '11 at 2:38
Try setting mydomain to your domain but adding/keeping in mydestination, also try adding to debug_peer_list = – rfelsburg Apr 11 '11 at 2:41

I was having issue when sending email from squirrelmail web interface. it said:

relay access denied

I fixed it by removing the following entry from my /etc/hosts:

::1     localhost ip6-localhost ip6-loopback
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.