AnsweredAssumed Answered

Send Email

Question asked by jay.kapalczynski on Oct 6, 2016
Latest reply on Oct 7, 2016 by Scott.Fierro

I am trying to send an email via python after my script runs...I am referencing this web page

How to send email in Python via SMTPLIB

 

I put in my Gmail user and password, not the one below...and run it...that's all I changed.

 

I get this error...wondering if anyone has done this before or have any other examples on how to do this.

Traceback (most recent call last):
File "C:/Users/tjv36463/Desktop/BearCollar/Python Files/ImportBearDataFiles_TestForExcel.py", line 62, in <module>
smtpserver = smtplib.SMTP("smtp.gmail.com",587)
File "C:\Python27\ArcGISx6410.3\lib\smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "C:\Python27\ArcGISx6410.3\lib\smtplib.py", line 311, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python27\ArcGISx6410.3\lib\smtplib.py", line 286, in _get_socket
return socket.create_connection((host, port), timeout)
File "C:\Python27\ArcGISx6410.3\lib\socket.py", line 571, in create_connection
raise err
error: [Errno 10013] An attempt was made to access a socket in a way forbidden by its access permissions
 

 

import smtplib

to = 'mkyong2002@yahoo.com'
gmail_user = 'mkyong2002@gmail.com'
gmail_pwd = 'yourpassword'
smtpserver = smtplib.SMTP("smtp.gmail.com",587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(gmail_user, gmail_pwd)
header = 'To:' + to + '\n' + 'From: ' + gmail_user + '\n' + 'Subject:testing \n'
print header
msg = header + '\n this is test msg from mkyong.com \n\n'
smtpserver.sendmail(gmail_user, to, msg)
print 'done!'
smtpserver.close()

Outcomes