In order to support a very large number of map consumers, that don't ever edit anything or create data, I rely on AGOL to host Map (Hosted Feature Services), hook those back to Portal as "Items", and keep my ArcGIS Server Farm service instances low, only spawning what is needed to support editors. Through security controls, the map service that automatically comes with a feature services is un-discoverable. I don't want people hitting the map services and spawning more service instances. This is in effect a "Collaboration"for people that can't enable Collaboration on their Portal.

https://www.esri.com/arcgis-blog/products/api-python/analytics/updating-your-hosted-feature-services-with-arcgis-pro-and-the-arcgis-api-for-python/ has been pretty handy for the past few years, via a scheduled task, it updates (nightly) several hundred feature services by pulling data from SDE into a Pro Project and overwriting what's on AGOL. Unfortunately, it doesn't allow you to preserve "Allow Export to other formats" setting on AGOL.
Enter https://pro.arcgis.com/en/pro-app/arcpy/sharing/introduction-to-arcpy-sharing.htm, which I've finally rolled my sleeves up on and have converted all my python doo-hickeys to use https://pro.arcgis.com/en/pro-app/arcpy/sharing/featuresharingdraft-class.htm, https://pro.arcgis.com/en/pro-app/tool-reference/server/stage-service.htm, and https://pro.arcgis.com/en/pro-app/tool-reference/server/upload-service-definition.htm. Coincidentally there's a lot more options to control service parameters.
Disclaimer: I know nothing about python, so I'm sure there's all sorts of inefficiencies in here, but it works.
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> sys<SPAN class="punctuation token">,</SPAN> string<SPAN class="punctuation token">,</SPAN> os<SPAN class="punctuation token">,</SPAN> calendar<SPAN class="punctuation token">,</SPAN> datetime<SPAN class="punctuation token">,</SPAN> traceback<SPAN class="punctuation token">,</SPAN>smtplib
<SPAN class="keyword token">from</SPAN> arcpy <SPAN class="keyword token">import</SPAN> env
<SPAN class="keyword token">from</SPAN> subprocess <SPAN class="keyword token">import</SPAN> call
<SPAN class="comment token"># Mail Server Settings</SPAN>
service <SPAN class="operator token">=</SPAN> <SPAN class="string token">"GRSM_SASQUATCH"</SPAN>
sd_filename <SPAN class="operator token">=</SPAN> service <SPAN class="operator token">+</SPAN> <SPAN class="string token">".sd"</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
d <SPAN class="operator token">=</SPAN> datetime<SPAN class="punctuation token">.</SPAN>datetime<SPAN class="punctuation token">.</SPAN>now<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
log <SPAN class="operator token">=</SPAN> open<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"C:\\PYTHON_LOGS\LOG."</SPAN><SPAN class="operator token">+</SPAN>service<SPAN class="operator token">+</SPAN><SPAN class="string token">".txt"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"a"</SPAN><SPAN class="punctuation token">)</SPAN>
log<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"----------------------------"</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\n"</SPAN><SPAN class="punctuation token">)</SPAN>
log<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"----------------------------"</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\n"</SPAN><SPAN class="punctuation token">)</SPAN>
log<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Log: "</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>d<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\n"</SPAN><SPAN class="punctuation token">)</SPAN>
log<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"\n"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Start process...</SPAN>
starttime <SPAN class="operator token">=</SPAN> datetime<SPAN class="punctuation token">.</SPAN>datetime<SPAN class="punctuation token">.</SPAN>now<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
log<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Begin process:\n"</SPAN><SPAN class="punctuation token">)</SPAN>
log<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">" Process started at "</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>starttime<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\n"</SPAN><SPAN class="punctuation token">)</SPAN>
log<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"\n"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Mail Server Settings</SPAN>
SERVER <SPAN class="operator token">=</SPAN> <SPAN class="string token">"1.2.34"</SPAN>
PORT <SPAN class="operator token">=</SPAN> <SPAN class="string token">"25"</SPAN>
FROM <SPAN class="operator token">=</SPAN> <SPAN class="string token">"sasquatch@big.foot.com"</SPAN>
MAILDOMAIN <SPAN class="operator token">=</SPAN> <SPAN class="string token">'@big.foot.com'</SPAN>
<SPAN class="comment token"># Data Steward getting the email. Needs to be their email address...without @big.foot.comat the end</SPAN>
userList<SPAN class="operator token">=</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">"yeti"</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># get a list of usernames from the list of named tuples returned from ListUsers</SPAN>
userNames <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>u <SPAN class="keyword token">for</SPAN> u <SPAN class="keyword token">in</SPAN> userList<SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># take the userNames list and make email addresses by appending the appropriate suffix.</SPAN>
emailList <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>name <SPAN class="operator token">+</SPAN> MAILDOMAIN <SPAN class="keyword token">for</SPAN> name <SPAN class="keyword token">in</SPAN> userNames<SPAN class="punctuation token">]</SPAN>
TO <SPAN class="operator token">=</SPAN> emailList
<SPAN class="comment token"># Grab date for the email</SPAN>
DATE <SPAN class="operator token">=</SPAN> d
<SPAN class="comment token"># Sign in to portal</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SignInToPortal<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'https://www.arcgis.com'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'userid'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'password'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Set output file names</SPAN>
outdir <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"C:\PRODUCTION\GRSM_SASQUATCH"</SPAN>
sddraft_filename <SPAN class="operator token">=</SPAN> service <SPAN class="operator token">+</SPAN> <SPAN class="string token">".sddraft"</SPAN>
sddraft_output_filename <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>outdir<SPAN class="punctuation token">,</SPAN> sddraft_filename<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#Delete any left over SD files from failed previous run</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
os<SPAN class="punctuation token">.</SPAN>remove<SPAN class="punctuation token">(</SPAN>sd_filename<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Successfully deleted "</SPAN><SPAN class="punctuation token">,</SPAN> sd_filename<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">except</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Error while deleting file "</SPAN><SPAN class="punctuation token">,</SPAN> sd_filename<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">", perhaps it doesn't exist"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
os<SPAN class="punctuation token">.</SPAN>remove<SPAN class="punctuation token">(</SPAN>sddraft_output_filename<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Successfully deleted "</SPAN><SPAN class="punctuation token">,</SPAN> sddraft_output_filename<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">except</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Error while deleting file "</SPAN><SPAN class="punctuation token">,</SPAN> sddraft_output_filename<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">", perhaps it doesn't exist"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Reference map to publish</SPAN>
aprx <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mp<SPAN class="punctuation token">.</SPAN>ArcGISProject<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">"C:\PRODUCTION\GRSM_SASQUATCH\GRSM_SASQUATCH.aprx"</SPAN><SPAN class="punctuation token">)</SPAN>
m <SPAN class="operator token">=</SPAN> aprx<SPAN class="punctuation token">.</SPAN>listMaps<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"GRSM_SASQUATCH_LOCATIONS"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># Create FeatureSharingDraft and set service properties</SPAN>
<SPAN class="comment token"># https://pro.arcgis.com/en/pro-app/arcpy/sharing/featuresharingdraft-class.htm</SPAN>
sharing_draft <SPAN class="operator token">=</SPAN> m<SPAN class="punctuation token">.</SPAN>getWebLayerSharingDraft<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"HOSTING_SERVER"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"FEATURE"</SPAN><SPAN class="punctuation token">,</SPAN> service<SPAN class="punctuation token">)</SPAN>
sharing_draft<SPAN class="punctuation token">.</SPAN>summary <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Sasquatch Locations"</SPAN>
sharing_draft<SPAN class="punctuation token">.</SPAN>tags <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Sasquatch, Fur, Hairy, Big Foot"</SPAN>
sharing_draft<SPAN class="punctuation token">.</SPAN>description <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Hide and Seek Champion"</SPAN>
sharing_draft<SPAN class="punctuation token">.</SPAN>credits <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Yeti"</SPAN>
sharing_draft<SPAN class="punctuation token">.</SPAN>useLimitations <SPAN class="operator token">=</SPAN> <SPAN class="string token">"This is not real"</SPAN>
<SPAN class="comment token">#sharing_draft.portalFolder = "Front Country"</SPAN>
sharing_draft<SPAN class="punctuation token">.</SPAN>overwriteExistingService <SPAN class="operator token">=</SPAN> <SPAN class="string token">"true"</SPAN>
sharing_draft<SPAN class="punctuation token">.</SPAN>allowExporting <SPAN class="operator token">=</SPAN> <SPAN class="string token">"true"</SPAN>
<SPAN class="comment token"># Create Service Definition Draft file</SPAN>
sharing_draft<SPAN class="punctuation token">.</SPAN>exportToSDDraft<SPAN class="punctuation token">(</SPAN>sddraft_output_filename<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Stage Service</SPAN>
<SPAN class="comment token"># https://pro.arcgis.com/en/pro-app/tool-reference/server/stage-service.htm</SPAN>
sd_output_filename <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>outdir<SPAN class="punctuation token">,</SPAN> sd_filename<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>StageService_server<SPAN class="punctuation token">(</SPAN>sddraft_output_filename<SPAN class="punctuation token">,</SPAN> sd_output_filename<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Share to portal</SPAN>
<SPAN class="comment token"># https://pro.arcgis.com/en/pro-app/tool-reference/server/upload-service-definition.htm</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Uploading Service Definition..."</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>UploadServiceDefinition_server<SPAN class="punctuation token">(</SPAN>sd_output_filename<SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"My Hosted Services"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"EXISTING"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"existingFolder"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"OVERRIDE_DEFINITION"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"SHARE_ONLINE"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"PUBLIC"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"SHARE_ORGANIZATION"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"GRSM"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"Great Smoky Mountains National Park Open Data"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Clean up SD files</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
os<SPAN class="punctuation token">.</SPAN>remove<SPAN class="punctuation token">(</SPAN>sd_filename<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Successfully deleted "</SPAN><SPAN class="punctuation token">,</SPAN> sd_filename<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">except</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Error while deleting file "</SPAN><SPAN class="punctuation token">,</SPAN> sd_filename<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">", perhaps it doesn't exist"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
os<SPAN class="punctuation token">.</SPAN>remove<SPAN class="punctuation token">(</SPAN>sddraft_output_filename<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Successfully deleted "</SPAN><SPAN class="punctuation token">,</SPAN> sddraft_output_filename<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">except</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Error while deleting file "</SPAN><SPAN class="punctuation token">,</SPAN> sddraft_output_filename<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">", perhaps it doesn't exist"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Write nothing to log if success.</SPAN>
endtime <SPAN class="operator token">=</SPAN> datetime<SPAN class="punctuation token">.</SPAN>datetime<SPAN class="punctuation token">.</SPAN>now<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
log<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">" Completed successfully in "</SPAN>
<SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>endtime <SPAN class="operator token">-</SPAN> starttime<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\n"</SPAN><SPAN class="punctuation token">)</SPAN>
log<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"\n"</SPAN><SPAN class="punctuation token">)</SPAN>
log<SPAN class="punctuation token">.</SPAN>close<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">'done'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">except</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token"># Get the traceback object</SPAN>
tb <SPAN class="operator token">=</SPAN> sys<SPAN class="punctuation token">.</SPAN>exc_info<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN>
tbinfo <SPAN class="operator token">=</SPAN> traceback<SPAN class="punctuation token">.</SPAN>format_tb<SPAN class="punctuation token">(</SPAN>tb<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># Concatenate information together concerning </SPAN>
<SPAN class="comment token"># the error into a message string</SPAN>
pymsg <SPAN class="operator token">=</SPAN> <SPAN class="string token">"PYTHON ERRORS:\nTraceback info:\n"</SPAN> <SPAN class="operator token">+</SPAN> tbinfo <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\nError Info:\n"</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>sys<SPAN class="punctuation token">.</SPAN>exc_info<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
msgs <SPAN class="operator token">=</SPAN> <SPAN class="string token">"ArcPy ERRORS:\n"</SPAN> <SPAN class="operator token">+</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetMessages<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\n"</SPAN>
<SPAN class="comment token"># Return python error messages for use in </SPAN>
<SPAN class="comment token"># script tool or Python Window</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddError<SPAN class="punctuation token">(</SPAN>pymsg<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddError<SPAN class="punctuation token">(</SPAN>msgs<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Print Python error messages for use in </SPAN>
<SPAN class="comment token"># Python / Python Window</SPAN>
log<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">""</SPAN> <SPAN class="operator token">+</SPAN> pymsg <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\n"</SPAN><SPAN class="punctuation token">)</SPAN>
log<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">""</SPAN> <SPAN class="operator token">+</SPAN> msgs <SPAN class="operator token">+</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">)</SPAN>
log<SPAN class="punctuation token">.</SPAN>close<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Define email message if something went wrong</SPAN>
SUBJECT <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Notification of Un-Successful AGOL Update of "</SPAN><SPAN class="operator token">+</SPAN>service
MSG <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Did Not Update: {} - ID: {} at "</SPAN><SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>DATE<SPAN class="punctuation token">)</SPAN><SPAN class="operator token">+</SPAN> <SPAN class="string token">"; "</SPAN> <SPAN class="operator token">+</SPAN>pymsg <SPAN class="operator token">+</SPAN> <SPAN class="string token">"; "</SPAN> <SPAN class="operator token">+</SPAN> msgs
<SPAN class="keyword token">print</SPAN> <SPAN class="punctuation token">(</SPAN>MSG<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="punctuation token">(</SPAN>emailList<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Send an email notifying steward of successful archive</SPAN>
<SPAN class="comment token">#MESSAGE = "\ From: %s To: %s Subject: %s %s" % (FROM, ", ".join(TO), SUBJECT, MSG)</SPAN>
MESSAGE <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Subject: %s\n\n%s"</SPAN> <SPAN class="operator token">%</SPAN> <SPAN class="punctuation token">(</SPAN>SUBJECT<SPAN class="punctuation token">,</SPAN> MSG<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Connecting to Server..."</SPAN><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>PORT<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Login..."</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Sending mail..."</SPAN><SPAN class="punctuation token">)</SPAN>
server<SPAN class="punctuation token">.</SPAN>sendmail<SPAN class="punctuation token">(</SPAN>FROM<SPAN class="punctuation token">,</SPAN> TO<SPAN class="punctuation token">,</SPAN> MESSAGE<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">except</SPAN> Exception <SPAN class="keyword token">as</SPAN> e<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Send Error Mail\n"</SPAN> <SPAN class="operator token">+</SPAN> e<SPAN class="punctuation token">.</SPAN>message<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">except</SPAN> Exception <SPAN class="keyword token">as</SPAN> e<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Error Authentication Server: check the credentials \n"</SPAN> <SPAN class="operator token">+</SPAN> e<SPAN class="punctuation token">.</SPAN>message<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">except</SPAN> Exception <SPAN class="keyword token">as</SPAN> e<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Error Connecting to Server : check the URL of the server and communications port ( 25 and ' the default ) \n"</SPAN> <SPAN class="operator token">+</SPAN> e<SPAN class="punctuation token">.</SPAN>message<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Quit."</SPAN><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">except</SPAN> Exception <SPAN class="keyword token">as</SPAN> e<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="punctuation token">(</SPAN>e<SPAN class="punctuation token">.</SPAN>message<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></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><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></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><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></SPAN><SPAN></SPAN></SPAN>