2

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[127.0.0.1]
Apr 11 00:50:27 unimatrix-01 postfix/smtpd[25212]: NOQUEUE: reject: RCPT from localhost[127.0.0.1]: 554 5.7.1 <[email protected]>: Relay access denied; from=<[email protected]> to=<[email protected]> proto=ESMTP helo=<unimatrix-01.example.com>
Apr 11 00:50:27 unimatrix-01 postfix/smtpd[25212]: lost connection after RSET from localhost[127.0.0.1]
Apr 11 00:50:27 unimatrix-01 postfix/smtpd[25212]: disconnect from localhost[127.0.0.1]

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.

3 Answers 3

4

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 127.0.0.1 is in $mynetworks. Just do,

sudo postconf mynetworks

and check if 127.0.0.1 is there.

2
  • 1
    Works for mee too added smtpd_recipient_restrictions = permit_mynetworks to /etc/postfix/main.cf and now python smtplib works to relay mail sent to localhost on to a given a relayhost.
    – here
    Feb 24, 2014 at 0:37
  • +1 @here, thanks for that. It saved me a frustrating evening! Nov 12, 2014 at 22:11
0

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 = gmail.com and then add gmail.com or $mydomain to mydestination.

Make sure to reload/restart postfix

4
  • PHP apps can setil send mail via mail(). Would your guess affect that as well?
    – Sean W.
    Apr 11, 2011 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, 2011 at 2:34
  • I tried as you suggested, and now postfix thinks that it's hosting the mailboxes for gmail.com Recipient address rejected: User unknown in local recipient table
    – Sean W.
    Apr 11, 2011 at 2:38
  • Try setting mydomain to your domain but adding/keeping gmail.com in mydestination, also try adding to main.cf: debug_peer_list = 127.0.0.1
    – rfelsburg
    Apr 11, 2011 at 2:41
-1

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

You must log in to answer this question.

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