Open a shell in the running container (e.g. docker exec -ti hass_container /bin/bash) and try to ping/telnet (port 25) your mailhost (172.17.42.1).
If that works, look at the mail logs on the mailhost when you try to send an email from home-assistant.
PING 172.17.42.1 (172.17.42.1): 56 data bytes
64 bytes from 172.17.42.1: icmp_seq=0 ttl=64 time=0.153 ms
64 bytes from 172.17.42.1: icmp_seq=1 ttl=64 time=0.299 ms
Added a -v /usr/bin/telnet:/usr/bin/telnet to docker config and now can use telnet…
telnet 172.17.42.1 25
Trying 172.17.42.1...
Connected to 172.17.42.1.
Escape character is '^]'.
220 mail-server ESMTP Postfix (Ubuntu)
^]
telnet> quit
Connection closed.
So I do get a connection now…
Wondering if the problem lies in my home-assistant config… as connection seems ok this way…
Ok, so the networking part works.
What do the mail logs say? Maybe the mail server does not accept connections from the 172.x.x.x network?
Or you need to add authentication information (username/password)?
You should see an error logged why it’s not accepting the mail from hass.
I see nothing in the /var/log/mail.log on the host. I’ve added 172.x.x.x network in my postfix config just in case.
By the way trying to run mailx in the docker image shows this:
mailx: /lib/x86_64-linux-gnu/libtinfo.so.5: no version information available (required by mailx)
mailx: /usr/lib/x86_64-linux-gnu/libssl.so.1.0.0: version `OPENSSL_1.0.2' not found (required by mailx)
Yeah, I don’t think you can just map the mailx binary into the container filespace and expect that to work.
When you telnet to the mailhost, you should at least see something like:
postfix/smtpd[45474]: connect from unknown[172.x.x.x]
If there’s no mentioning of a rejected email, you could try to send an email via telnet from the container:
# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 my_mailserver ESMTP Postfix
MAIL FROM: me@here
250 2.1.0 Ok
RCPT TO: me@there
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
foo bar baz
.
250 2.0.0 Ok: queued as 51B1520670D9
QUIT
221 2.0.0 Bye
Connection closed by foreign host.
In your case, you should either get a status code of 250 which means the mail was accepted, or an error message with a hint of why it’s not working.
16-11-13 11:48:00 ERROR (ThreadPool Worker 5) [homeassistant.core] BusHandler:Exception doing job
Traceback (most recent call last):
File "/usr/src/app/homeassistant/core.py", line 1210, in job_handler
func(*args)
File "/usr/src/app/homeassistant/core.py", line 1065, in execute_service
service_handler.func(service_call)
File "/usr/src/app/homeassistant/components/notify/__init__.py", line 110, in notify_message
notify_service.send_message(**kwargs)
File "/usr/src/app/homeassistant/components/notify/smtp.py", line 138, in send_message
return self._send_email(msg)
File "/usr/src/app/homeassistant/components/notify/smtp.py", line 146, in _send_email
msg.as_string())
File "/usr/local/lib/python3.5/smtplib.py", line 856, in sendmail
(code, resp) = self.mail(from_addr, esmtp_opts)
File "/usr/local/lib/python3.5/smtplib.py", line 533, in mail
self.putcmd("mail", "FROM:%s%s" % (quoteaddr(sender), optionlist))
File "/usr/local/lib/python3.5/smtplib.py", line 153, in quoteaddr
if addrstring.strip().startswith('<'):
AttributeError: 'NoneType' object has no attribute 'strip'
Mails were not accepted by postfix at first. They were first rejected (code 550 I believe), so changed the sender to a correct name. After that they appeared to be stuck in the mail queue.
Final solution in my case was to also include username next to the sender address, eg: