import smtplib
# creates SMTP session
s = smtplib.SMTP('smtp.mail.outlook.com', 587)
s.elho()
# start TLS for security
s.starttls()
# Authentication
s.login("xxx@amdocs.com", "fdgre")
# message to be sent
message = "Hello"
# sending the mail
s.sendmail("xxx@amdocs.com", "yyy@amdocs.com", message)
# terminating the session
s.quit()
错误:
C:\Users\SOURAVS\PycharmProjects\TEST\venv\Scripts\python.exe C:/Users/SOURAVS/PycharmProjects/TEST/mailcheck.py
Traceback (most recent call last):
File "C:/Users/SOURAVS/PycharmProjects/TEST/mailcheck.py", line 4, in <module>
s = smtplib.SMTP('smtp.mail.outlook.com', 587)
File "C:\Users\SOURAVS\AppData\Local\Programs\Python\Python37-32\lib\smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "C:\Users\SOURAVS\AppData\Local\Programs\Python\Python37-32\lib\smtplib.py", line 336, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Users\SOURAVS\AppData\Local\Programs\Python\Python37-32\lib\smtplib.py", line 307, in _get_socket
self.source_address)
File "C:\Users\SOURAVS\AppData\Local\Programs\Python\Python37-32\lib\socket.py", line 707, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "C:\Users\SOURAVS\AppData\Local\Programs\Python\Python37-32\lib\socket.py", line 748, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed