<?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 outlook smtp server connection in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-outlook-smtp-server-connection/m-p/25586#M1932</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The referenced thread is quite long and there are a lot of code snippets.&amp;nbsp; It would be helpful if you paste the specific code you are using here.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 04 Sep 2018 16:34:18 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2018-09-04T16:34:18Z</dc:date>
    <item>
      <title>Python outlook smtp server connection</title>
      <link>https://community.esri.com/t5/python-questions/python-outlook-smtp-server-connection/m-p/25585#M1931</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have been trying to utilize Jake's solution located here &lt;A _jive_internal="true" class="link-titled" href="https://community.esri.com/docs/DOC-10163-send-email-when-a-feature-is-added-to-a-arcgis-online-hosted-feature-service#comments" title="https://community.esri.com/docs/DOC-10163-send-email-when-a-feature-is-added-to-a-arcgis-online-hosted-feature-service#comments"&gt;https://community.esri.com/docs/DOC-10163-send-email-when-a-feature-is-added-to-a-arcgis-online-hosted-feature-service#c…&lt;/A&gt; to send an email from outlook when a new feature is added. However, I keep receiving the falling traceback error:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt;&amp;nbsp; File "C:\Users\twhitley\Documents\check_update2b.py", line 66, in &amp;lt;module&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; smtpObj.sendmail(FROM, TO, message)&lt;BR /&gt;&amp;nbsp; File "C:\Python27\ArcGIS10.3\lib\smtplib.py", line 723, in sendmail&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.rset()&lt;BR /&gt;&amp;nbsp; File "C:\Python27\ArcGIS10.3\lib\smtplib.py", line 462, in rset&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return self.docmd("rset")&lt;BR /&gt;&amp;nbsp; File "C:\Python27\ArcGIS10.3\lib\smtplib.py", line 387, in docmd&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return self.getreply()&lt;BR /&gt;&amp;nbsp; File "C:\Python27\ArcGIS10.3\lib\smtplib.py", line 363, in getreply&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise SMTPServerDisconnected("Connection unexpectedly closed")&lt;BR /&gt;SMTPServerDisconnected: Connection unexpectedly closed&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;My python parameters for outlook are this:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;SPAN&gt;fromEmail = &lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:'awhitley@peachtree-city.org"&gt;'awhitley@peachtree-city.org&lt;/A&gt;&lt;SPAN&gt;' # Email sender&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;toEmail = &lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:'awhitley@peachtree-city.org"&gt;'awhitley@peachtree-city.org&lt;/A&gt;&lt;SPAN&gt;'&amp;nbsp;&amp;nbsp; # Email receiver&lt;/SPAN&gt;&lt;BR /&gt;smtpServer = 'smtp-mail.outlook.com'&amp;nbsp;&amp;nbsp;&amp;nbsp; # SMPT Server Name&lt;BR /&gt;portNumber = 587&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;&amp;nbsp; # SMTP Server port&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Can someone point me in the right direction; the script Generates the token as expected but seems to hang at the SMTP settings. #&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Sep 2018 15:40:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-outlook-smtp-server-connection/m-p/25585#M1931</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2018-09-04T15:40:17Z</dc:date>
    </item>
    <item>
      <title>Re: Python outlook smtp server connection</title>
      <link>https://community.esri.com/t5/python-questions/python-outlook-smtp-server-connection/m-p/25586#M1932</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The referenced thread is quite long and there are a lot of code snippets.&amp;nbsp; It would be helpful if you paste the specific code you are using here.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Sep 2018 16:34:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-outlook-smtp-server-connection/m-p/25586#M1932</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2018-09-04T16:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: Python outlook smtp server connection</title>
      <link>https://community.esri.com/t5/python-questions/python-outlook-smtp-server-connection/m-p/25587#M1933</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sure; the actual code is here: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;import urllib2, json, urllib, datetime, time, smtplib&lt;BR /&gt;from datetime import timedelta&lt;BR /&gt;&lt;BR /&gt;# Variables&lt;BR /&gt;username = 'awhitley67'&amp;nbsp;&amp;nbsp;&amp;nbsp; # AGOL Username&lt;BR /&gt;password = 'xxxxxxxxxxx'&amp;nbsp;&amp;nbsp;&amp;nbsp; # AGOL Password&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;URL = '&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fservices5.arcgis.com%2FixWnd9c3gwqSeniI%2Farcgis%2Frest%2Fservices%2FRoadProblemReports%2FFeatureServer%2F0%2Fquery" rel="nofollow" target="_blank"&gt;https://services5.arcgis.com/ixWnd9c3gwqSeniI/arcgis/rest/services/RoadProblemReports/FeatureServer/0/query&lt;/A&gt;&lt;SPAN&gt;'&amp;nbsp; # Feature Service URL&lt;/SPAN&gt;&lt;BR /&gt;uniqueID = 'OBJECTID'&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # i.e. OBJECTID&lt;BR /&gt;dateField = 'CreationDate'&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Date field to query&lt;BR /&gt;hoursValue = 1&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Number of hours to check when a feature was added&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;fromEmail = &lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:'awhitley@peachtree-city.org"&gt;'awhitley@peachtree-city.org&lt;/A&gt;&lt;SPAN&gt;' # Email sender&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;toEmail = &lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:'awhitley@peachtree-city.org"&gt;'awhitley@peachtree-city.org&lt;/A&gt;&lt;SPAN&gt;'&amp;nbsp;&amp;nbsp; # Email receiver&lt;/SPAN&gt;&lt;BR /&gt;smtpServer = smtp-mail.outlook.com'&amp;nbsp;&amp;nbsp;&amp;nbsp; # SMPT Server Name&lt;BR /&gt;portNumber = 587&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;&amp;nbsp; # SMTP Server port&lt;BR /&gt;&lt;BR /&gt;# Create empty list for uniqueIDs&lt;BR /&gt;oidList = []&lt;BR /&gt;&lt;BR /&gt;# Generate AGOL token&lt;BR /&gt;try:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print('Generating Token')&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; tokenURL = '&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fwww.arcgis.com%2Fsharing%2Frest%2FgenerateToken" rel="nofollow" target="_blank"&gt;https://www.arcgis.com/sharing/rest/generateToken&lt;/A&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; params = {'f': 'pjson', 'username': username, 'password': password, 'referer': '&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Fwww.arcgis.com" rel="nofollow" target="_blank"&gt;http://www.arcgis.com&lt;/A&gt;&lt;SPAN&gt;'}&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; req = urllib2.Request(tokenURL, urllib.urlencode(params))&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; response = urllib2.urlopen(req)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data = json.load(response)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; token = data['token']&lt;BR /&gt;except:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; token = ''&lt;BR /&gt;&lt;BR /&gt;# Query service and check if created_date time is within the last hour&lt;BR /&gt;params = {'f': 'pjson', 'where': "1=1", 'outfields' : '{0}, {1}'.format(uniqueID, dateField), 'returnGeometry' : 'false', 'token' : token}&lt;BR /&gt;req = urllib2.Request(URL, urllib.urlencode(params))&lt;BR /&gt;response = urllib2.urlopen(req)&lt;BR /&gt;data = json.load(response)&lt;BR /&gt;for feat in data['features']:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; createDate = feat['attributes'][dateField]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; createDate = int(str(createDate)[0:-3])&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; t = datetime.datetime.now() - timedelta(hours=hoursValue)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; t = time.mktime(t.timetuple())&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if createDate &amp;gt; t:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; oidList.append(feat['attributes'][uniqueID])&lt;BR /&gt;&lt;BR /&gt;print(oidList)&lt;BR /&gt;&lt;BR /&gt;# Email Info&lt;BR /&gt;FROM = fromEmail&lt;BR /&gt;TO = [toEmail]&lt;BR /&gt;SUBJECT = 'New Features Added'&lt;BR /&gt;TEXT = "Features with {0}s {1} were added.".format(uniqueID, oidList)&lt;BR /&gt;&lt;BR /&gt;message = """\&lt;BR /&gt;From: %s&lt;BR /&gt;To: %s&lt;BR /&gt;Subject: %s&lt;BR /&gt;&lt;BR /&gt;%s&lt;BR /&gt;""" % (FROM, ", ".join(TO), SUBJECT, TEXT)&lt;BR /&gt;&lt;BR /&gt;# If new features exist, send email&lt;BR /&gt;if len(oidList) &amp;gt; 0:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; smtpObj = smtplib.SMTP(host=smtpServer, port=portNumber)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; smtpObj.sendmail(FROM, TO, message)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Successfully sent email"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; smtpObj.quit()&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Sep 2018 18:25:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-outlook-smtp-server-connection/m-p/25587#M1933</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2018-09-04T18:25:04Z</dc:date>
    </item>
    <item>
      <title>Re: Python outlook smtp server connection</title>
      <link>https://community.esri.com/t5/python-questions/python-outlook-smtp-server-connection/m-p/25588#M1934</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I suspect your smtp server is wanting authorization.&amp;nbsp; This page &lt;A href="https://www.authsmtp.com/python/index.html"&gt;https://www.authsmtp.com/python/index.html&lt;/A&gt;&amp;nbsp;has a summary of the steps.&amp;nbsp; See also: &lt;A href="https://support.office.com/en-us/article/pop-imap-and-smtp-settings-for-outlook-com-d088b986-291d-42b8-9564-9c414e2aa040"&gt;POP, IMAP, and SMTP settings for Outlook.com&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EDIT:&amp;nbsp; In the thread you mentioned, &lt;A href="https://community.esri.com/migrated-users/8586"&gt;Jake Skinner&lt;/A&gt;‌ shared a link (&lt;A href="https://stackabuse.com/how-to-send-emails-with-gmail-using-python/"&gt;How to Send Emails with Gmail using Python&lt;/A&gt;) which also describes the authorization process.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Sep 2018 19:32:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-outlook-smtp-server-connection/m-p/25588#M1934</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2018-09-04T19:32:59Z</dc:date>
    </item>
  </channel>
</rss>

