My issue is that when I run the following code, I get a WinError 10061, and from all of my searching it looks like this is a result of the foreign machine not being set up properly, but I assume that Google has that taken care of for gmail, so the error lies on my side. All of the other examples I could find were using localhost and getting this error, and it was because they did not have a local mail server set up. Would that still be the case with this problem? I am sure I am missing something obvious. Also, the error code is in full. Thank you in advance!
import smtplib
fromaddr = 'email@email.com'
toaddrs = 'otheremail@email.com'
msg = 'Random stuff!'
username = 'username'
password = 'pass'
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(username,password)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
Error:
Traceback (most recent call last):
File "C:/Users/Brett/PycharmProjects/Texting/sendMessage.py", line 13, in <module>
server = smtplib.SMTP('smtp.gmail.com')
File "C:\Python33\lib\smtplib.py", line 238, in __init__
(code, msg) = self.connect(host, port)
File "C:\Python33\lib\smtplib.py", line 317, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python33\lib\smtplib.py", line 288, in _get_socket
self.source_address)
File "C:\Python33\lib\socket.py", line 424, in create_connection
raise err
File "C:\Python33\lib\socket.py", line 415, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it