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")