Receiving getaddrinfo [Errno -2] when trying to use Beaglebone Black to send email
<p>I'm trying to use a Beaglebone Black (BBB) to send email notifications, but I'm getting caught up on this getaddrinfo error that reads as follows; </p>

<blockquote>
  <p>socket.gaierror: [Errno -2] Name or service not known</p>
</blockquote>

<p>I've been working on this for a while and can't find why this isn't working. </p>

<p>The nano file I"m trying to run:</p>

<pre><code>import smtplib
#import time
smtpObj = smtplib.SMTP('smtp.gmail.com', 587)
#time.sleep(1000)
print("SMTP object created...")
smtpObj.ehlo()
#time.sleep(1000)
print("EHLO...")
smtpObj.starttls()
#time.sleep(1000)
print("Starting TLS...")
smtpObj.login('EXAMPLEACCOUNT@gmail.com', 'EXAMPLEPASSWORD')
#time.sleep(1000)
print("Logged into EXAMPLEACCOUNT@gmail.com...")
smtpObj.sendmail('EXAMPLEACCOUNT@gmail.com', 'EXAMPLERECIPIENT', '''Subject:test subject \ntest body
Auto Alert System.''')
{}
#time.sleep(1000)
print("Sending email...")
smtpObj.quit()
#time.sleep(1000)
print("Destorying object.")
</code></pre>

<p>The output of invoking the test_email2.py function is as follows:</p>

<pre><code>root@beaglebone:~/Desktop/email_project# python test_email2.py
Traceback (most recent call last):
File "test_email2.py", line 4, in &lt;module&gt;
smtpObj = smtplib.SMTP('smtp.gmail.com', 587)
File "/usr/lib/python2.7/smtplib.py", line 249, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python2.7/smtplib.py", line 309, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python2.7/smtplib.py", line 284, in _get_socket
return socket.create_connection((port, host), timeout)
File "/usr/lib/python2.7/socket.py", line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno -2] Name or service not known
</code></pre>

<p>The format I've been following is based on that provided by <a href="https://automatetheboringstuff.com/chapter16/" rel="nofollow">https://automatetheboringstuff.com/chapter16/</a></p>

<p><code>socket.gaierror</code> means that (underlying in libc) <code>getaddrinfo</code> function failed to get IP addresses for domain names you provided. It explains why it failed: <code>[Errno -2] Name or service not known</code>, so it doesn't know about a domain with such a name, <code>smtp.gmail.com</code>. This domain name obviously exists, so you should look into DNS system settings in your BBB system (and it's actually more of a SuperUser community question).</p>

<p>What DNS servers are used in configuration? If you're using a local caching DNS server at loopback, is it up and running? Is it configured properly to allow recursive requests? This particular problem most likely has nothing to do with Python or your code; it's your BBB system cannot resolve at least some, if not all, domain names.</p>

python email smtp beagleboneblack errno