<?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: Send me an email telling me if my geoprocessing task failed or was successful in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/send-me-an-email-telling-me-if-my-geoprocessing/m-p/1162503#M53823</link>
    <description>&lt;P&gt;Okay thanks!&amp;nbsp; I will try to incorporate that and see if I can get it to work.&lt;/P&gt;</description>
    <pubDate>Fri, 08 Apr 2022 13:07:36 GMT</pubDate>
    <dc:creator>MelissaJohnson</dc:creator>
    <dc:date>2022-04-08T13:07:36Z</dc:date>
    <item>
      <title>Send me an email telling me if my geoprocessing task failed or was successful</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/send-me-an-email-telling-me-if-my-geoprocessing/m-p/1160969#M53636</link>
      <description>&lt;P&gt;I have a model that I have been using the Scheduled Task to run.&amp;nbsp; I am finding that it fails at times (sometimes my drive gets disconnected and the model doesn't know what to do, since Pro doesn't seem to use the UNC path in the model it causes a failure)sure, but I have no way of knowing unless I open it every day and look.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to see if there is a way to get an email, or other kind of notification that it has run and either succeeded or failed to complete as it should.&amp;nbsp; Is there a way to do that using Python?&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Melissa&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 21:23:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/send-me-an-email-telling-me-if-my-geoprocessing/m-p/1160969#M53636</guid>
      <dc:creator>MelissaJohnson</dc:creator>
      <dc:date>2022-04-04T21:23:27Z</dc:date>
    </item>
    <item>
      <title>Re: Send me an email telling me if my geoprocessing task failed or was successful</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/send-me-an-email-telling-me-if-my-geoprocessing/m-p/1160983#M53639</link>
      <description>&lt;P&gt;Though I'm not familiar scheduling Models with task scheduler, for python scripts, I use sendmail for that.&lt;/P&gt;&lt;P&gt;In my script, I have a Mailer() function&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import smtplib
from email.mime.text import MIMEText

msgtext = 'default text for message'
subtext = 'default text for subject'

def Mailer():
     ############################################
     ##Variables to set for notification emails##
     ############################################
     server = smtplib.SMTP(MSERV)
     TO = [MTO]             # set to email you want results sent to
     FROM = MFROM         # set to email you want results sent FROM
     msg = MIMEText( msgtext )
     msg['Subject'] = subtext
     msg['From'] = FROM
     msg['To'] = ','.join(TO)
     server.sendmail(FROM, TO, msg.as_string())
     server.quit()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If there are any errors, the except: block modifies the msgtext and subtext to include error message stuff:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;msgtext = '--ERROR----------ERROR----------ERROR----------ERROR--\nPYTHON ERRORS:\nTraceback Info:\n' + tbinfo + '\nError Info:\n' + str(sys.exc_type) + ': ' + str(sys.exc_value) + '\n'
subtext = 'Program Failed.'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then, in my finally: block, I run&lt;/P&gt;&lt;P&gt;Mailer()&lt;/P&gt;&lt;P&gt;This way, I always get an email with default message UNLESS there was an error, then I get the error as well.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 22:32:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/send-me-an-email-telling-me-if-my-geoprocessing/m-p/1160983#M53639</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2022-04-04T22:32:13Z</dc:date>
    </item>
    <item>
      <title>Re: Send me an email telling me if my geoprocessing task failed or was successful</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/send-me-an-email-telling-me-if-my-geoprocessing/m-p/1162503#M53823</link>
      <description>&lt;P&gt;Okay thanks!&amp;nbsp; I will try to incorporate that and see if I can get it to work.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2022 13:07:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/send-me-an-email-telling-me-if-my-geoprocessing/m-p/1162503#M53823</guid>
      <dc:creator>MelissaJohnson</dc:creator>
      <dc:date>2022-04-08T13:07:36Z</dc:date>
    </item>
    <item>
      <title>Re: Send me an email telling me if my geoprocessing task failed or was successful</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/send-me-an-email-telling-me-if-my-geoprocessing/m-p/1183585#M56256</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/15530"&gt;@RhettZufelt&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;This is great.&amp;nbsp; Is there anyway you could show your whole script?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Heath&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2022 15:39:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/send-me-an-email-telling-me-if-my-geoprocessing/m-p/1183585#M56256</guid>
      <dc:creator>HeathAnderson</dc:creator>
      <dc:date>2022-06-16T15:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: Send me an email telling me if my geoprocessing task failed or was successful</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/send-me-an-email-telling-me-if-my-geoprocessing/m-p/1183607#M56260</link>
      <description>&lt;P&gt;Sure, at least the email reporting part.&lt;/P&gt;&lt;P&gt;Lines 7 &amp;amp;&amp;nbsp; 8 set my default email message and subject.&lt;/P&gt;&lt;P&gt;If an exception occurs, the msgtext and subtext variables are overwritten to include error information in the except: block.&lt;/P&gt;&lt;P&gt;After the script is finished, the Mailer() def is run from the finally: block and sends the email with original message if no errors, or with modified message if exception thrown.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy, os, traceback, sys, smtplib
from email.mime.text import MIMEText

##########################################################
####      Def to eMail progress reports to user       ####
##########################################################
compname = os.getenv('COMPUTERNAME')
subtext = "   Report of " + os.path.basename((inspect.getfile(lambda:None))) + " From " + compname
msgtext = "   Message from " + os.path.basename((inspect.getfile(lambda:None))) + " running on " + compname + "\n"

def Mailer():
    ############################################
    ##Variables to set for notification emails##
    ############################################
    server = smtplib.SMTP(MSERV)
    TO = [MTO]             # set to email you want results sent to
    FROM = MFROM           # set to email you want results sent FROM
    msg = MIMEText( msgtext )
    msg['Subject'] = subtext
    msg['From'] = FROM
    msg['To'] = ','.join(TO)
    server.sendmail(FROM, TO, msg.as_string())
    server.quit()


def Work():
    ##   put working commands here

    #  This is where I put the working python    
    
try:
  if __name__ == "__main__":    # Funny statement to keep from running module on import.
                                # though, this module not designed to be imported.
    Work()   

except:
    tb = sys.exc_info()[2]
    tbinfo = traceback.format_tb(tb)[0]
    msgtext = '--ERROR----------ERROR----------ERROR----------ERROR--\nPYTHON ERRORS:\nTraceback Info:\n' + tbinfo + '\nError Info:\n' + str(sys.exc_type) + ': ' + str(sys.exc_value) + '\n'
    subtext = 'Program Failed.'

finally:
    #Do Stuff here at end of run
    Mailer()   #  Send the email &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2022 15:58:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/send-me-an-email-telling-me-if-my-geoprocessing/m-p/1183607#M56260</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2022-06-16T15:58:17Z</dc:date>
    </item>
    <item>
      <title>Re: Send me an email telling me if my geoprocessing task failed or was successful</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/send-me-an-email-telling-me-if-my-geoprocessing/m-p/1183923#M56307</link>
      <description>&lt;P&gt;Hi R_,&lt;/P&gt;&lt;P&gt;The script is working well.&amp;nbsp; Thank you.&amp;nbsp; The only thing is that the python error isn't coming through in the body of the email.&amp;nbsp; The script is only returning the following line.&amp;nbsp; Any thoughts?&lt;/P&gt;&lt;P&gt;msgtext = " Message from " + os.path.basename((inspect.getfile(lambda:None))) + " running on " + compname + "\n"&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Heath&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jun 2022 15:30:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/send-me-an-email-telling-me-if-my-geoprocessing/m-p/1183923#M56307</guid>
      <dc:creator>HeathAnderson</dc:creator>
      <dc:date>2022-06-17T15:30:05Z</dc:date>
    </item>
    <item>
      <title>Re: Send me an email telling me if my geoprocessing task failed or was successful</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/send-me-an-email-telling-me-if-my-geoprocessing/m-p/1183943#M56310</link>
      <description>&lt;P&gt;Sorry, guess I stripped off one too many imports. Looks like I included some that aren't needed also.&lt;/P&gt;&lt;P&gt;Should just need to add inspect to the imports:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import os, sys, traceback, smtplib, inspect&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, that line is just trying to add the name of the script.py file that is running as all my scripts include this.&amp;nbsp; that way, I know what script fired it.&lt;/P&gt;&lt;P&gt;You can always customize the message to suit your needs.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jun 2022 16:06:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/send-me-an-email-telling-me-if-my-geoprocessing/m-p/1183943#M56310</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2022-06-17T16:06:24Z</dc:date>
    </item>
  </channel>
</rss>

