Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have read A LOT of places of people trying to solve this problem and none of them have worked for me. I have the following script

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

msg = MIMEMultipart('alternative')
msg['Subject'] = "[Test Email]"
msg['From'] = "email@domain.biz"
msg['To'] = "email@domain.com"

text = "sample Email"
html = "<html><body>sampleEmail</body></html>"
textPart = MIMEText(text, 'plain')
htmlPart = MIMEText(html, 'html')
msg.attach(textPart)
msg.attach(htmlPart)

s = smtplib.SMTP("localhost")
s.set_debuglevel(1)
s.sendmail("email@domain.biz","email@domain.com", msg.as_string())
s.quit()

When I run the script on server a (call it domain.com), everything works as expected. When I run the script on server b (call it domain.biz), I get Relay Access Denied. On server b I tried to set up my own postfix instance for domain.biz (and wasn't entirely successful), and I something might be messed up from that.

Everything I have read says that the local SMTP Server is not allowing to relay to (or from?) this address. Someone suggested I make sure smtpd_recipient_restrictions includes permit_mynetworks:

sudo postconf smtpd_recipient_restrictions

which printed:

smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination

So that looks good (Could the problem be reject_unauth_destination?).

Then they said make sure the ip address is included in mynetworks so:

sudo postconf mynetworks

which prints:

mynetworks = 10.0.0.0/16, 192.168.1.0/24, 127.0.0.0/8, 55.55.55.0/24, .domain.com, .domain.biz, .ip-55-55-55-55.ip.secureserver.net

As you can see I added every domain I could think of. (note 55.55.55.55 is not the real IP).

The error message says:

python2.7 emailTest.py
send: 'ehlo localhost.localdomain\r\n'
reply: '250-domain.biz\r\n'
reply: '250-PIPELINING\r\n'
reply: '250-SIZE 10240000\r\n'
reply: '250-VRFY\r\n'
reply: '250-ETRN\r\n'
reply: '250-ENHANCEDSTATUSCODES\r\n'
reply: '250-8BITMIME\r\n'
reply: '250 DSN\r\n'
reply: retcode (250); Msg: domain.biz
PIPELINING
SIZE 10240000
VRFY
ETRN
ENHANCEDSTATUSCODES
8BITMIME
DSN
send: 'mail FROM:<email@domain.biz> size=565\r\n'
reply: '250 2.1.0 Ok\r\n'
reply: retcode (250); Msg: 2.1.0 Ok
send: 'rcpt TO:<email@domain.com>\r\n'
reply: '554 5.7.1 <email@domain.com>: Relay access denied\r\n'
reply: retcode (554); Msg: 5.7.1 <email@domain.com>: Relay access denied
send: 'rset\r\n'
reply: '250 2.0.0 Ok\r\n'
reply: retcode (250); Msg: 2.0.0 Ok
Traceback (most recent call last):
  File "emailTest.py", line 122, in <module>
    s.sendmail("email@domain.biz","email@domain.com", msg.as_string())
  File "/usr/local/lib/python2.7/smtplib.py", line 734, in sendmail
    raise SMTPRecipientsRefused(senderrs)
smtplib.SMTPRecipientsRefused: {'email@domain.com': (554, '5.7.1 <email@domain.com>: Relay access denied')}

Additional main.cf info:

> sudo postconf mydestination
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, mail.$mydomain, www.$mydomain, ftp.$mydomain
> sudo postconf relay_domains
relay_domains = $mydestination
> sudo postconf mynetworks_style
mynetworks_style = subnet
> sudo postconf relayhost
relayhost = 
>sudo postconf mydomain
mydomain = domain.biz

I also tried:

sudo postconf relayhost
relayhost = [mail.$mydomain]

Postfix log says:

> sudo tail -10 /var/log/maillog
...
Jan 21 12:26:36 ip-50-62-42-49 postfix/smtpd[3875]: connect from localhost[::1]
Jan 21 12:26:36 ip-50-62-42-49 postfix/trivial-rewrite[3877]: warning: do not list domain domain.biz in BOTH mydestination and virtual_alias_domains
Jan 21 12:26:36 ip-50-62-42-49 postfix/smtpd[3875]: NOQUEUE: reject: RCPT from localhost[::1]: 554 5.7.1 <email@domain.com>: Relay access denied; from=<email@domain.biz> to=<email@domain.com> proto=ESMTP helo=<localhost.localdomain>
Jan 21 12:26:36 ip-50-62-42-49 postfix/smtpd[3875]: lost connection after RSET from localhost[::1]
Jan 21 12:26:36 ip-50-62-42-49 postfix/smtpd[3875]: disconnect from localhost[::1]

sudo postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 1
html_directory = no
inet_interfaces = all
inet_protocols = all
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
masquerade_domains = $mydomain
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, mail.$mydomain, www.$mydomain, ftp.$mydomain
mydomain = domain.biz
myhostname = domain.biz
mynetworks = 10.0.0.0/16, 192.168.1.0/24, 127.0.0.0/8, 55.55.55.0/24, .domain.com, .domain.biz, .ip-55-55-55-55.ip.secureserver.net
myorigin = $mydomain
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
relayhost = [mail.$mydomain]
sample_directory = /usr/share/doc/postfix-2.6.6/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
unknown_local_recipient_reject_code = 550
virtual_alias_domains = domain.biz
virtual_alias_maps = hash:/etc/postfix/virtual

I changed the IP addresses and the ipaddresses.

UPDATE:

After Weeks of trying to get this working and thanks to everyone's assistance I found the solution. I was trying to use localhost as the relayhost, but because this is a godaddy hosted server all relays must go through a designated relayhost. All I needed to do was change the location of the SMTP. The line is now:

s = smtplib.SMTP("dedrelay.secureserver.net")
share|improve this question
    
What's your relay host configuration in your main.cf? My past experience in similar issues point to the fact that the relay server is expecting credentials (possibly sasl authentication) from your server. It doesn't find anything and hence it is rejecting access. –  Mukul Jan 21 at 19:09
    
What's you /etc/postfix/main.cf look like? Check out postfix.org/BASIC_CONFIGURATION_README.html#relay_from to see how to setup your relays. By default postfix is usually configured to send directly. –  Russell Shingleton Jan 21 at 19:09
    
@RussellShingleton See the end of the post. I added info from main.cf. Looks like this is related to relayhost being empty. What should it be? –  ajon Jan 21 at 19:20
    
and what does postfix log say ? –  Bartłomiej Zarzecki Jan 21 at 19:24
    
@BartłomiejZarzecki I added the log to the bottom of the post. Obviously I replaced email with the address and domain with the real domain. –  ajon Jan 21 at 19:30

1 Answer 1

up vote 1 down vote accepted

There are few areas you (may) need to setup in the /etc/postfix/main.cf. If you are using you web host's smtp server as a relay for instance, you would want to look for the section with "relayhost =".

According to What delivery method: direct or indirect:

By default, Postfix tries to deliver mail directly to the Internet. Depending on your local conditions this may not be possible or desirable. For example, your system may be turned off outside office hours, it may be behind a firewall, or it may be connected via a provider who does not allow direct mail to the Internet. In those cases you need to configure Postfix to deliver mail indirectly via a relay host.

Examples (specify only one of the following):

/etc/postfix/main.cf:

relayhost =                   (default: direct delivery to Internet)
relayhost = $mydomain         (deliver via local mailhub)
relayhost = [mail.$mydomain]  (deliver via local mailhub)
relayhost = [mail.isp.tld]    (deliver via provider mailhub)

The form enclosed with [ ] eliminates DNS MX lookups. Don't worry if you don't know what that means. Just be sure to specify the [ ] around the mailhub hostname that your ISP gave to you, otherwise mail may be mis-delivered.

Your default config should have something like the above. Choose a valid config based on your setup and comment out the others.

I would also suggest reviewing other sections regarding relays and network config to see if your setup is up to spec: Postfix Basic Configuration

share|improve this answer
    
This prompted me to talk to GoDaddy who hosts the VPS and they informed me all relays must go through their designated servers, so I can't use localhost. Thanks for the help!!! –  ajon Jan 21 at 21:16

Your Answer

 
discard

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.