Why does my mailing script work outside of rc.local but not when I run rc.local?


I have ubuntu 18.04 and I recently added the rc.local script to /etc/ so I could run my emailing script to email myself my IP address from my jetson nano computer. I need it to email me because I cannot setup a static IP and the IP changes occasionally. The computer will be setup on a 1:16 RC race car so I have to ssh into it.

I used this tutorial to setup ssmtp on ubuntu: https://stackoverflow.com/questions/38391412/raspberry-pi-send-mail-from-command-line-using-gmail-smtp-server

I used this tutorial to attempt to run the script I show below on startup on ubuntu 18.04: https://www.linuxbabe.com/linux-server/how-to-enable-etcrc-local-with-systemd

This is my emailIP.sh :

#!/bin/bash STR="$  (/sbin/ifconfig)"  echo "$  STR" | ssmtp my.email@gmail.com 

It is a very simple script and it works when i run it using sh emailIP.sh

When I run sudo systemctl start rc-local.service and then run sudo systemctl status rc-local.service

I get this output:

 ● rc-local.service - /etc/rc.local Compatibility    Loaded: loaded (/etc/systemd/system/rc-local.service; enabled; vendor preset: enabled)   Drop-In: /lib/systemd/system/rc-local.service.d            └─debian.conf    Active: active (exited) since Sat 2019-03-23 14:45:28 CDT; 15min ago   Process: 4391 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)  Mar 23 14:45:28 servanh-desktop systemd[1]: Starting /etc/rc.local Compatibility... Mar 23 14:45:28 servanh-desktop rc.local[4391]: ssmtp: Cannot open smtp.gmail.com:587 Mar 23 14:45:28 servanh-desktop sSMTP[4497]: Unable to locate smtp.gmail.com Mar 23 14:45:28 servanh-desktop sSMTP[4497]: Cannot open smtp.gmail.com:587 Mar 23 14:45:28 servanh-desktop systemd[1]: Started /etc/rc.local Compatibility. 

So what I am not understanding is why it is giving me this Unable to locate smtp.gmail.com error when its in my /etc/ssmtp/ssmtp.conf and if that file was not configured correctly then my script would not run when I do sh emailIP.sh?