I am new to using smtplib and wanted to used it to automate the mass-mail sending process in my company. I tried this basic script -
#!/usr/bin/env python
import smtplib
server = smtplib.SMTP('smtp.gmail.com:587')
user_mail = '[user_email]@gmail.com'
user_pwd = '[password]'
rcv_mail = '[reciever_email]@yahoo.com'
msg = 'Test'
server.login(user_mail, user_pwd)
server.ehlo()
server.starttls()
server.sendmail(user_mail, rcv_mail, msg)
server.quit()
I am not using this script as is in my program, this is just to get a hang of how smtplib works. I'm getting this error
Traceback (most recent call last):
File "sampleSMTP.py", line 4, in <module>
server = smtplib.SMTP('smtp.gmail.com. 587')
File "/usr/local/lib/python2.7/smtplib.py", line 256, in __init__
(code, msg) = self.connect(host, port)
File "/usr/local/lib/python2.7/smtplib.py", line 316, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/local/lib/python2.7/smtplib.py", line 291, in _get_socket
return socket.create_connection((host, port), timeout)
File "/usr/local/lib/python2.7/socket.py", line 557, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno -2] Name or service not known
Previously in other iterations I have tried using MIMEMultipart and MIMEText from the email module, and I have got as output other Exceptions too, like ServerAuthenticationError (<- I did some print debugging in this one and found that the exception was raised from the server.login() statement).
My request is, can someone explain to me these exceptions and tell me what I need to do to get rid of them? I dont need a working code, just a good explanation.
Edit: There had been a syntax error previously, which I corrected. The Exception is now this:
Traceback (most recent call last):
File "sampleSMTP.py", line 10, in <module>
server.login(user_mail, user_pwd)
File "/usr/local/lib/python2.7/smtplib.py", line 585, in login
raise SMTPException("SMTP AUTH extension not supported by server.")
smtplib.SMTPException: SMTP AUTH extension not supported by server.
My original question stands - how and why are these exceptions caused in smtplib methods, and how can I resolve them?