SMTP Suddenly Stopped Working

Hi!

I’m kinda new to Home Assistant, but I’m slowly get things working. I’ve managed to debug most, but this has me totally stumped. I have looked at a few issues around SMTP, but I can’t seem to find one that mirrors this…

I managed to get it working last week, for a few great days, but then it stopped! I think it was due to some router-level updates I made - the issues started some time shortly after a few small updates.

  • I have a modem that feeds into a router - all my home things sit behind the second router. I did make a change where I connected this second router to VPN, meaning that the server sits behind the VPN.
  • I noticed some unknown ports being forwarded on my stock modem, so I factory reset it. I’m not really a “port forwarding person”, so I don’t think I would have changed too much on here.
  • I added some additional things to the config file - just to get the correct “latitude” etc, as the VPN was causing it to be picked up incorrectly.

At some point after the above, it seemed like the system stopped sending emails.

I have emailed separately from the account (without HA) and it works, so I don’t believe it’s an issue with the VPN, but I suppose it could be…

Can anyone help???

CONFIG:


notify:
  - platform: smtp
    name: alert_test
    server: smtp.gmail.com
    timeout: 15
    port: 587
    encryption: starttls
    sender: xxx
    sender_name: xxx
    starttls: 1
    username: xxx
    password: xxx
    recipient: 
    - xxx

The error I get is definitely related to the setup of the SMTP, but I don’t know exactly what the issue is.

Error setting up platform smtp
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/notify/__init__.py", line 78, in async_setup_platform
    platform.get_service, hass, p_config, discovery_info
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/smtp/notify.py", line 84, in get_service
    if mail_service.connection_is_valid():
  File "/usr/src/homeassistant/homeassistant/components/smtp/notify.py", line 138, in connection_is_valid
    server = self.connect()
  File "/usr/src/homeassistant/homeassistant/components/smtp/notify.py", line 124, in connect
    mail = smtplib.SMTP(self._server, self._port, timeout=self._timeout)
  File "/usr/local/lib/python3.7/smtplib.py", line 251, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/local/lib/python3.7/smtplib.py", line 336, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/local/lib/python3.7/smtplib.py", line 307, in _get_socket
    self.source_address)
  File "/usr/local/lib/python3.7/socket.py", line 727, in create_connection
    raise err
  File "/usr/local/lib/python3.7/socket.py", line 716, in create_connection
    sock.connect(sa)
OSError: [Errno 101] Network unreachable

Okay…

After more investigation… This IS a VPN thing…

Connecting my router to the VPN disallows the sending of emails from the server that’s sat within my network…

So… the question has changed…

Does anyone know a solution to this? So that I can get the system to send emails while still on a VPN?

Is the system itself on a VPN? If so, then whomever is providing the VPN needs to allow outbound port 587 connections. It appears it is not. You’re getting a “Network Unreachable” error, which implies the VPN is blocking the connections.

Thanks so much, @pickerin!

The system itself is on the VPN, but so are other items (as they are sat behind the router).

The thing that confuses me is that I can send emails from things inside the VPN (from the exact same account), so I was wondering whether it might be the VPN itself causing the issue, or the system that Home Assistant is running on (Synology NAS) - I should add that I haven’t tried (because I don’t know how to) send emails directly from the NAS itself, I’ve emailed from a PC on the same network…

Welrdly, the NAS (within its own log) is also telling me that it cannot send the email, so it’s difficult to determine exactly where the issue lies - although it is clear that it has something to do with the VPN.

Bearing in mind that I can still send emails form inside it, is there a chance that it’s not the VPN directly, but something else?? I’ll contact the VPN provider directly anyway!

I just jumped back on here to ask another email-related question, and I realised that I never came back to this one.

In case anyone stumbles across this - the notification works now and I can send emails from behind the VPN.

I must admit that I don’t recall exactly what I did here, but my system does still sit behind the VPN and I didn’t tunnel/open ports.

In case it helps, below is from my config. I think this is pretty standard though, so unlikely to be new info.

notify:
  - name: send_an_email
    platform: smtp
    server: smtp.gmail.com
    sender: redacted@redacted
    sender_name: anyname
    encryption: starttls
    username: redacted@redacted
    password: redacted
    recipient: 
    - redacted@redacted