Title: Getting error while sending email using Python
Tags: python;email
Question: When I try sending an email from Python I get an error message. By the way I made less secure configuration and IMAP Enable on gmail account. Here is the code below:
```import smtplib

sender_email=&quot;davidvalencia@example.net&quot;
receveir_email=&quot;davidvalencia@example.net&quot;
password=input(&quot;please enter your password&quot;)
message=&quot;this email  from python &quot;

server=smtplib.SMTP_SSL('smptp.gmail.com',587)

server.ehlo
server.starttls()
server.login(sender_email,password)
print(&quot;login success&quot;)
server.sendmail(sender_email,receveir_email,message)
print(&quot;email has been sent to&quot;,receveir_email)
server.close()
```
My error message:
```Traceback (most recent call last):
  File &quot;C:/Users/Administrator/PycharmProjects/codebook/Training0718.py&quot;, line 23, in <module&gt;
    server=smtplib.SMTP_SSL('smptp.gmail.com',465)
  File &quot;C:\Program Files\Python38\lib\smtplib.py&quot;, line 1034, in __init__
    SMTP.__init__(self, host, port, local_hostname, timeout,
  File &quot;C:\Program Files\Python38\lib\smtplib.py&quot;, line 253, in __init__
    (code, msg) = self.connect(host, port)
  File &quot;C:\Program Files\Python38\lib\smtplib.py&quot;, line 339, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File &quot;C:\Program Files\Python38\lib\smtplib.py&quot;, line 1040, in _get_socket
    new_socket = socket.create_connection((host, port), timeout,
  File &quot;C:\Program Files\Python38\lib\socket.py&quot;, line 787, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File &quot;C:\Program Files\Python38\lib\socket.py&quot;, line 918, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed
```

Comment: You have a typo in the SMTP host.


Here is another answer: I was able to make it work with the following, note that this will only succeed if you have created and are using an app password
```import smtplib


password = input('please enter your password')

to = 'davidvalencia@example.net'
_from = 'davidvalencia@example.net'
message = 'hello'

try:
    server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
    server.ehlo()
    server.login(_from, password)
    server.sendmail(_from, to, message)
    server.close()

except Exception as err:
    print(err)
```


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:07/18/20', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<python><email>', 'Title': 'Getting error while sending email using Python', 'ViewCount': 682, 'id': 62972702, 'user_AboutMe': None, 'user_AccountId': 14936924.0, 'user_DisplayName': 'Basit Anlat', 'user_Reputation': 27.0, 'user_Views': 13.0, 'user_id': 10784667.0}}