I'm trying to run this script which searches for approval dates with the current date and sends out emailed alerts to each customer. I keep getting an error when running 'name cursor' is not defined.
<SPAN class="keyword token">import</SPAN> arcpy<SPAN class="punctuation token">,</SPAN> datetime<SPAN class="punctuation token">,</SPAN> smtplib
<SPAN class="keyword token">from</SPAN> arcgis <SPAN class="keyword token">import</SPAN> GIS
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
<SPAN class="comment token">#Location of ArcPro project with AGOL layer added into map content</SPAN>
prjPath <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\Python\UtilityEncroachment_Active\Update\Update.aprx'</SPAN>
<SPAN class="comment token">#Create layer object of service being updated.</SPAN>
proj <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mp<SPAN class="punctuation token">.</SPAN>ArcGISProject<SPAN class="punctuation token">(</SPAN>prjPath<SPAN class="punctuation token">)</SPAN>
map <SPAN class="operator token">=</SPAN> proj<SPAN class="punctuation token">.</SPAN>listMaps<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
layer <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">.</SPAN>listLayers<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
field <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'Date_Approved'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Email'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Applicant'</SPAN><SPAN class="punctuation token">]</SPAN>
today <SPAN class="operator token">=</SPAN> datetime<SPAN class="punctuation token">.</SPAN>datetime<SPAN class="punctuation token">.</SPAN>today<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
tdy <SPAN class="operator token">=</SPAN> datetime<SPAN class="punctuation token">.</SPAN>datetime<SPAN class="punctuation token">.</SPAN>strftime<SPAN class="punctuation token">(</SPAN>today<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'%Y-%m-%d'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>layer<SPAN class="punctuation token">,</SPAN> field<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Date_Approved = {}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>tdy<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> email_cursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Match Found!"</SPAN><SPAN class="punctuation token">)</SPAN>
SERVER <SPAN class="operator token">=</SPAN> <SPAN class="string token">"xyz"</SPAN>
FROM <SPAN class="operator token">=</SPAN> <SPAN class="string token">"xyz@xyz.com"</SPAN>
TO <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Applicant <{}>"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
CC <SPAN class="operator token">=</SPAN> <SPAN class="string token">"xyz"</SPAN>
SUBJECT <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Utility Encroachment Approach Approved"</SPAN>
MSG <SPAN class="operator token">=</SPAN> <SPAN class="string token">"\n {},\n"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">" "</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"This is to notify you that your utility encroachment has been approved. Please use the following link to view additional details www. .com"</SPAN>
TEXT <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>MSG<SPAN class="punctuation token">)</SPAN>
MESSAGE <SPAN class="operator token">=</SPAN> <SPAN class="string token">'Subject: {}\n\n{}'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>SUBJECT<SPAN class="punctuation token">,</SPAN> TEXT<SPAN class="punctuation token">)</SPAN>
server <SPAN class="operator token">=</SPAN> smtplib<SPAN class="punctuation token">.</SPAN>SMTP<SPAN class="punctuation token">(</SPAN>SERVER<SPAN class="punctuation token">)</SPAN>
server<SPAN class="punctuation token">.</SPAN>sendmail<SPAN class="punctuation token">(</SPAN>FROM<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN>TO<SPAN class="punctuation token">]</SPAN><SPAN class="operator token">+</SPAN><SPAN class="punctuation token">[</SPAN>CC<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> MESSAGE<SPAN class="punctuation token">)</SPAN>
server<SPAN class="punctuation token">.</SPAN>quit<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Email notifications sent."</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>