socket.gaierror: [Errno 11001] getaddrinfo failed. Cant send mail through smtplib

Viewed 581

I am trying to send a mail using python with the module SMTPLIB, I followed the instructions of this video https://www.youtube.com/watch?v=JRCJ6RtE3xU

Here is the code

import os
import smtplib

with smtplib.SMTP('stmp.gmail.com', 587) as smtp:
    smtp.ehlo()
    smtp.starttls()
    smtp.ehlo()

    smtp.login('example@gmail.com', 'examplepassword')

    Email_subject = '2 Factor Authentication Code'
    Email_body = "Hello"

    msg = f'Subject: {Email_subject}\n\n{body}'

    smtp.sendmail('example@gmail.com', 'example@gmail.com', msg)

Here is the error that I'm getting

Traceback (most recent call last):
  File "e:/Programming/Intaf/Production_Register/Malingtry.py", line 7, in <module>
    with smtplib.SMTP('stmp.gmail.com', 587) as smtp:
  File "C:\Users\myname\AppData\Local\Programs\Python\Python36\lib\smtplib.py", line 251, in __init__
    (code, msg) = self.connect(host, port)
  File "C:\Users\myname\AppData\Local\Programs\Python\Python36\lib\smtplib.py", line 336, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "C:\Users\myname\AppData\Local\Programs\Python\Python36\lib\smtplib.py", line 307, in _get_socket
    self.source_address)
  File "C:\Users\myname\AppData\Local\Programs\Python\Python36\lib\socket.py", line 704, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "C:\Users\myname\AppData\Local\Programs\Python\Python36\lib\socket.py", line 745, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed
PS E:\Programming\Intaf\Production_Register> 
0 Answers
Related