I'm working on a guessing game where there are tons of characters and it gives you hints for you to guess the character. There is also going to be a thing where you can submit a character. I want to do it so that it will send me an e-mail if somebody submits a character, but it's not working. Here's my code:
import smtplib
FROM = 'Guess@Character.com'
TO = ["mikpe120@gmail.com"] # must be a list
SUBJECT = "Somebody submitted a character!"
TEXT = "Name: " + name + "NameType: " + nameType
# Prepare actual message
message = """\
From: %s
To: %s
Subject: %s
%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
# Send the mail
server = smtplib.SMTP('myserver')
server.sendmail(FROM, TO, message)
server.quit()
And here is the error that I got:
Traceback (most recent call last):
File "C:/Users/Mikolaj Perzyna/Desktop/addCharacter.py", line 106, in <module>
server = smtplib.SMTP('myserver')
File "C:\Users\Mikolaj Perzyna\AppData\Local\Programs\Python\Python36\lib\smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "C:\Users\Mikolaj Perzyna\AppData\Local\Programs\Python\Python36\lib\smtplib.py", line 335, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Users\Mikolaj Perzyna\AppData\Local\Programs\Python\Python36\lib\smtplib.py", line 306, in _get_socket
self.source_address)
File "C:\Users\Mikolaj Perzyna\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\Mikolaj Perzyna\AppData\Local\Programs\Python\Python36\lib\socket.py", line 743, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed
I'm sorry if I'm formatting this post wrong, which I probably am, but this is my first question on the site.
getaddrinfo failed
means that the socket connection smptlib.SMTP
uses failed to resolve the hostname of the server. Try a different SMTP server or a different IP/hostname.
This line is almost certainly wrong.
server = smtplib.SMTP('myserver')
Is your SMTP server really called myserver
? I'd expect to see something like mail.mydomain.com
there.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.