<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python smtplib module breaking arcpy? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-smtplib-module-breaking-arcpy/m-p/489504#M38283</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Like Matt said, I too think your Python install is hosed...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;See how stmplib is "looking" under: C:\Python26\lib\smtplib.py... With ArcGIS properly installed the stmplib library should be located under C:\Python26\ArcGIS10.0\Lib. If you have both a C:\Python26\lib folder and a C:\Python26\ArcGIS10.0 folder I can almost 99.9 % assure you that your Pythoin install is to blame. Not sure why things would all of a sudden start working after a few weeks.... that seems weird, but...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As a test, I would recommend on one of your boxes you:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Unstall ArcGIS completely&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Uninstall any and all Python versions including any Python extras like PythonWin.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3. Delete the C:\Program Files\ArcGIS folder.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4. Delete any C:\Python* folders&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;5. Delete the C:\Users\&amp;lt;usernames&amp;gt;\AppData\Roaming\ESRI folder&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;6. Reinstall ArcGIS&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;7. After all that, it "should" be back to normal.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 17 Dec 2012 19:11:58 GMT</pubDate>
    <dc:creator>ChrisSnyder</dc:creator>
    <dc:date>2012-12-17T19:11:58Z</dc:date>
    <item>
      <title>Python smtplib module breaking arcpy?</title>
      <link>https://community.esri.com/t5/python-questions/python-smtplib-module-breaking-arcpy/m-p/489500#M38279</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In my organization we have Python scripts used for data checks, which use ArcPy (ArcGIS 10.0 SP4) and also the smtplib modul,e so we can receive automated emails regarding data errors. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Problem we are finding is if try these scripts on our laptops. Not only cannot get script to connect to email server (which is not a problem I expect help for here), but it also semi-permanently breaking ArcPy AFTER failing to connect to email server via smtp module. I cannot understand why the two are linked? Simplest case from command prompt:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
C:\&amp;gt;python

Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on

win32

Type "help", "copyright", "credits" or "license" for more information.

&amp;gt;&amp;gt;&amp;gt; import smtplib

&amp;gt;&amp;gt;&amp;gt; server=smtplib.SMTP('&amp;lt;MAIL SERVER&amp;gt;') 

Traceback (most recent call last):

&amp;nbsp; File "&amp;lt;stdin&amp;gt;", line 1, in &amp;lt;module&amp;gt;

&amp;nbsp; File "C:\Python26\lib\smtplib.py", line 239, in __init__

&amp;nbsp;&amp;nbsp;&amp;nbsp; (code, msg) = self.connect(host, port)

&amp;nbsp; File "C:\Python26\lib\smtplib.py", line 295, in connect

&amp;nbsp;&amp;nbsp;&amp;nbsp; self.sock = self._get_socket(host, port, self.timeout)

&amp;nbsp; File "C:\Python26\lib\smtplib.py", line 273, in _get_socket

&amp;nbsp;&amp;nbsp;&amp;nbsp; return socket.create_connection((port, host), timeout)

&amp;nbsp; File "C:\Python26\lib\socket.py", line 514, in create_connection

&amp;nbsp;&amp;nbsp;&amp;nbsp; raise error, msg

socket.error: [Errno 10061] No connection could be made because the target machine actively refused it

&amp;gt;&amp;gt;&amp;gt; import arcpy
Traceback (most recent call last):
&amp;nbsp; File "&amp;lt;stdin&amp;gt;", line 1, in &amp;lt;module&amp;gt;
&amp;nbsp; File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\__init__.py", line 17, i
n &amp;lt;module&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; from geoprocessing import gp
&amp;nbsp; File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\__init__.p
y", line 14, in &amp;lt;module&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; from _base import *
&amp;nbsp; File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py",
 line 568, in &amp;lt;module&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; env = GPEnvironments(gp)
&amp;nbsp; File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py",
 line 565, in GPEnvironments
&amp;nbsp;&amp;nbsp;&amp;nbsp; return GPEnvironment(geoprocessor)
&amp;nbsp; File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py",
 line 521, in __init__
&amp;nbsp;&amp;nbsp;&amp;nbsp; self._refresh()
&amp;nbsp; File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py",
 line 523, in _refresh
&amp;nbsp;&amp;nbsp;&amp;nbsp; envset = (set(env for env in self._gp.listEnvironments()))
RuntimeError: NotInitialized

&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now, ArcPy is broken on this laptop, running any ArcPy script with or without smtplib module. If I tried a script from a Toolbox, or any script with import ArcPy it will fail with the above error. I can import arcgisscripting successfully, however.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Rebooting makes no difference, uninstalling Python and ArcGIS 10.0 makes no difference. However, over time (maybe a week or two) ArcPy returns. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I just wondered if anyone had experienced this? There is a definite link with smtplib causing the problem to the ArcPy module and have reproduced it on multiple laptops here, never desktop PCs where the same is fine. Thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Dec 2012 13:40:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-smtplib-module-breaking-arcpy/m-p/489500#M38279</guid>
      <dc:creator>TomWilson2</dc:creator>
      <dc:date>2012-12-17T13:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: Python smtplib module breaking arcpy?</title>
      <link>https://community.esri.com/t5/python-questions/python-smtplib-module-breaking-arcpy/m-p/489501#M38280</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Your smtp error is most likely due to your server listening on a different port than default. To correct for this you will have to specify which port you want to connect to.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Have you tried installing Python using the default settings? Your paths indicate you had a previous version of python installed prior to installing ArcGIS or used some other customization for your python install. Are you sure you are on version 2.6.5?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Dec 2012 14:28:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-smtplib-module-breaking-arcpy/m-p/489501#M38280</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-12-17T14:28:36Z</dc:date>
    </item>
    <item>
      <title>Re: Python smtplib module breaking arcpy?</title>
      <link>https://community.esri.com/t5/python-questions/python-smtplib-module-breaking-arcpy/m-p/489502#M38281</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;To get my machine to send emails via Python, I had to get our sysadmin people to unblock port 25.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Otherwise you can specify another port - for example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def sendEmail(emailServer, login, password, port, to, fro = "", subject="", text="", files=[]):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Sends an email using a specified mail server and your username credentials"""
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; import smtplib
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from email.MIMEMultipart import MIMEMultipart
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from email.MIMEBase import MIMEBase
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from email.MIMEText import MIMEText
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from email.Utils import COMMASPACE, formatdate
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from email import Encoders
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; msg = MIMEMultipart()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; msg['From'] = fro
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; msg['To'] = COMMASPACE.join(to)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; msg['Date'] = formatdate(localtime = True)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; msg['Subject'] = subject
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; msg.attach(MIMEText(text))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for file in files:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; part = MIMEBase('application',"octet-stream")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; part.set_payload(open(file,"rb").read())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Encoders.encode_base64(part)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; part.add_header('Content-Disposition','attachment; filename="%s"' %os.path.basename(file))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; msg.attach(part)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #try to connect to the email server
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; server = smtplib.SMTP()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;server.connect(emailServer, port) #port = 25 or 587 or ?&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if login != "" and password != "":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; server.ehlo()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; server.starttls()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; server.ehlo()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; server.login(login, password)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; server.sendmail(fro,to,msg.as_string())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; server.quit()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; server.close()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return True
&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return False&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:32:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-smtplib-module-breaking-arcpy/m-p/489502#M38281</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T21:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: Python smtplib module breaking arcpy?</title>
      <link>https://community.esri.com/t5/python-questions/python-smtplib-module-breaking-arcpy/m-p/489503#M38282</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the suggestions. It is not really the email functionality I am posting about here.&amp;nbsp; smtplib works fine for us to email when script used on desktop PCs/ servers and we can live with this as a scheduled task would not normally be set on laptops.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What I really would like to resolve is why this failed attempt to connect to email server via smtplib on our laptops breaks the ability to import ArcPy afterwards. Users will normally test a script on the first thing to hand. In our case if tried script using smtplib and it only simply failed to run/ email results this would be fine- I know not to use a laptop if need that working. The problem, however, is this failed attempt to connect via smtplib has for some reason broken the ability to import ArcPy and run any arcpy script whether smtplib is involved or not.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;mzcoyle - the Python home is different under the example I showed as I uninstalled and re-installed Python to attempt to fix the problem when it first occurred, which made no difference. Python home was intially C:\Python26\ArcGIS10.0\. I know about setting the Desktop10.pth under site-packages. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have been using ArcPy fine from the current home for a while. Then test the smtplib connection again- it breaks ability to import arcpy for a week or two and then for seemingly no reason it's back. I have no idea what breaks and fixes it, hence this post.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Dec 2012 18:11:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-smtplib-module-breaking-arcpy/m-p/489503#M38282</guid>
      <dc:creator>TomWilson2</dc:creator>
      <dc:date>2012-12-17T18:11:34Z</dc:date>
    </item>
    <item>
      <title>Re: Python smtplib module breaking arcpy?</title>
      <link>https://community.esri.com/t5/python-questions/python-smtplib-module-breaking-arcpy/m-p/489504#M38283</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Like Matt said, I too think your Python install is hosed...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;See how stmplib is "looking" under: C:\Python26\lib\smtplib.py... With ArcGIS properly installed the stmplib library should be located under C:\Python26\ArcGIS10.0\Lib. If you have both a C:\Python26\lib folder and a C:\Python26\ArcGIS10.0 folder I can almost 99.9 % assure you that your Pythoin install is to blame. Not sure why things would all of a sudden start working after a few weeks.... that seems weird, but...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As a test, I would recommend on one of your boxes you:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Unstall ArcGIS completely&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Uninstall any and all Python versions including any Python extras like PythonWin.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3. Delete the C:\Program Files\ArcGIS folder.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4. Delete any C:\Python* folders&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;5. Delete the C:\Users\&amp;lt;usernames&amp;gt;\AppData\Roaming\ESRI folder&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;6. Reinstall ArcGIS&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;7. After all that, it "should" be back to normal.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Dec 2012 19:11:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-smtplib-module-breaking-arcpy/m-p/489504#M38283</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2012-12-17T19:11:58Z</dc:date>
    </item>
  </channel>
</rss>

