<?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: Notebook - Create a .csv from feature service - Send Email to a user with .csv attachment in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/notebook-create-a-csv-from-feature-service-send/m-p/1404754#M9834</link>
    <description>&lt;P&gt;Good luck! I hope it does what you need it to do. Glad I could help a little bit.&lt;/P&gt;&lt;P&gt;Many thanks ed&lt;/P&gt;</description>
    <pubDate>Tue, 02 Apr 2024 17:46:26 GMT</pubDate>
    <dc:creator>EdMorris</dc:creator>
    <dc:date>2024-04-02T17:46:26Z</dc:date>
    <item>
      <title>Notebook - Create a .csv from feature service - Send Email to a user with .csv attachment</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/notebook-create-a-csv-from-feature-service-send/m-p/1403958#M9828</link>
      <description>&lt;P&gt;The code is generating the .csv, but I am lost when sending an email. Any help would be excellent.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# Function to send an email with attachment&lt;/P&gt;&lt;P&gt;UserList = []&lt;BR /&gt;users = gis.users.search(max_users=10000)&lt;BR /&gt;#print(users)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;emails_of_user = [member.email for member in users]&lt;BR /&gt;#print(emails_of_user)&lt;/P&gt;&lt;P&gt;# Find the user with the specified email address&lt;BR /&gt;unique_user = next((member for member in users if member.email == 'christopher.mask@ag.ok.gov'), None)&lt;/P&gt;&lt;P&gt;# Check if the user with the specified email is found&lt;BR /&gt;if unique_user:&lt;BR /&gt;print("Unique user found:")&lt;BR /&gt;print("Username:", unique_user.username)&lt;BR /&gt;print("Email:", unique_user.email)&lt;BR /&gt;group.notify(users=unique_user, subject= "Test Message", message="Testing the notification system",method="email")&lt;BR /&gt;&lt;BR /&gt;else:&lt;BR /&gt;print("User with email not found.")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;print results are:&lt;/P&gt;&lt;PRE&gt;CSV file exported successfully to: HistoricalFireOccurrence_VFD_LastMonth.csv
Unique user found:
Username: CMask_OKForestry
Email: christopher.mask@ag.ok.gov&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not even sure this can be done with notebook.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Christopher Mask&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2024 17:45:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/notebook-create-a-csv-from-feature-service-send/m-p/1403958#M9828</guid>
      <dc:creator>ChristopherMask</dc:creator>
      <dc:date>2024-04-01T17:45:38Z</dc:date>
    </item>
    <item>
      <title>Re: Notebook - Create a .csv from feature service - Send Email to a user with .csv attachment</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/notebook-create-a-csv-from-feature-service-send/m-p/1404427#M9829</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;So, as I understand it, you now want to send an email using the ArcGIS API for Python?&lt;/P&gt;&lt;P&gt;You may want to have a look at the &lt;STRONG&gt;send_notification()&lt;/STRONG&gt; method. It is found on the &lt;EM&gt;admin.UserManager&lt;/EM&gt; class and can be used with ArcGIS Online. I think it is deprecated for ArcGIS Enterprise 10.9....&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2024 09:38:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/notebook-create-a-csv-from-feature-service-send/m-p/1404427#M9829</guid>
      <dc:creator>EdMorris</dc:creator>
      <dc:date>2024-04-02T09:38:32Z</dc:date>
    </item>
    <item>
      <title>Re: Notebook - Create a .csv from feature service - Send Email to a user with .csv attachment</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/notebook-create-a-csv-from-feature-service-send/m-p/1404561#M9831</link>
      <description>&lt;P&gt;The method worked and thank you for the insight. Is there a way to send an attachment in the email?&lt;/P&gt;&lt;P&gt;gis.users.send_notification([unique_user], "A new file has been created","Please download the new file", type = 'email')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2024 13:32:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/notebook-create-a-csv-from-feature-service-send/m-p/1404561#M9831</guid>
      <dc:creator>ChristopherMask</dc:creator>
      <dc:date>2024-04-02T13:32:32Z</dc:date>
    </item>
    <item>
      <title>Re: Notebook - Create a .csv from feature service - Send Email to a user with .csv attachment</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/notebook-create-a-csv-from-feature-service-send/m-p/1404662#M9832</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I'm not sure the API is capable of sending attachments when emails are generated by the API.&lt;/P&gt;&lt;P&gt;Perhaps you can embed a link to where your file is in your Portal, in your email using the following as a guide:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/python-questions/new-line-in-notification-and-email/td-p/1093174" target="_blank"&gt;(3) New Line in notification and email - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;and then your user(s) can download it from the portal.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2024 15:30:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/notebook-create-a-csv-from-feature-service-send/m-p/1404662#M9832</guid>
      <dc:creator>EdMorris</dc:creator>
      <dc:date>2024-04-02T15:30:39Z</dc:date>
    </item>
    <item>
      <title>Re: Notebook - Create a .csv from feature service - Send Email to a user with .csv attachment</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/notebook-create-a-csv-from-feature-service-send/m-p/1404731#M9833</link>
      <description>&lt;P&gt;Sounds good. I have modified the code and created a task for the notebook to be executed at 12:00AM. Here is the final code and I appreciate the feedback, Ed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;from arcgis.gis import GIS&lt;BR /&gt;import datetime as dt&lt;BR /&gt;import pandas as pd&lt;BR /&gt;from datetime import datetime, timedelta&lt;/P&gt;&lt;P&gt;# Connect to your GIS&lt;BR /&gt;gis = GIS('home')&lt;/P&gt;&lt;P&gt;query = 'title: "HistoricalFireOccurrence" AND type: "Feature Service"'&lt;BR /&gt;search_results = gis.content.search(query=query, max_items=10)&lt;/P&gt;&lt;P&gt;HistoricalFireOccurrence_item = search_results[0]&lt;BR /&gt;HistoricalFireOccurrence_layer = HistoricalFireOccurrence_item.layers[0]&lt;/P&gt;&lt;P&gt;# Calculate the date range for the last month&lt;BR /&gt;end_date = datetime.now()&lt;BR /&gt;start_date = end_date - timedelta(days=31)&lt;/P&gt;&lt;P&gt;# Format the dates in a way that SQL can understand&lt;BR /&gt;start_date_str = start_date.strftime("%Y-%m-%d")&lt;BR /&gt;end_date_str = end_date.strftime("%Y-%m-%d")&lt;/P&gt;&lt;P&gt;# Define the where clause&lt;BR /&gt;where_clause = f"District = 'VFD' AND CreationDate BETWEEN '{start_date_str}' AND '{end_date_str}'"&lt;/P&gt;&lt;P&gt;# Retrieve features with the where clause applied&lt;BR /&gt;features = HistoricalFireOccurrence_layer.query(where=where_clause)&lt;/P&gt;&lt;P&gt;# Convert the features to a pandas DataFrame&lt;BR /&gt;df = features.df&lt;/P&gt;&lt;P&gt;# Export the DataFrame to a CSV file&lt;BR /&gt;csv_file_path = "HistoricalFireOccurrence_VFD_LastMonth.csv"&lt;BR /&gt;df.to_csv(csv_file_path, index=False)&lt;/P&gt;&lt;P&gt;print(f"CSV file exported successfully to: {csv_file_path}")&lt;/P&gt;&lt;P&gt;# Get the user you want to send the notification to&lt;BR /&gt;user1 = gis.users.get("CMask_OKForestry")&lt;BR /&gt;user2 = gis.users.get("cmask_noadmin")&lt;/P&gt;&lt;P&gt;# List of users to send the notification&lt;BR /&gt;recipients = [user1, user2]&lt;/P&gt;&lt;P&gt;# Check if the user with the specified email is found&lt;BR /&gt;if len(recipients) &amp;gt; 0:&lt;BR /&gt;messageSubject = 'This is a message from cmask_okforestry'&lt;BR /&gt;messageMessage = f'A new fire department file has been created and is ready to download. Please login to AGO. The file can be found by clicking Notebook, Open VFD Fire Occurrence Data Export, Click Files, Click on the file name to download: {csv_file_path}'&lt;BR /&gt;gis.users.send_notification(recipients, messageSubject, messageMessage, type='email')&lt;BR /&gt;else:&lt;BR /&gt;print("User with email not found.")&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2024 17:15:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/notebook-create-a-csv-from-feature-service-send/m-p/1404731#M9833</guid>
      <dc:creator>ChristopherMask</dc:creator>
      <dc:date>2024-04-02T17:15:40Z</dc:date>
    </item>
    <item>
      <title>Re: Notebook - Create a .csv from feature service - Send Email to a user with .csv attachment</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/notebook-create-a-csv-from-feature-service-send/m-p/1404754#M9834</link>
      <description>&lt;P&gt;Good luck! I hope it does what you need it to do. Glad I could help a little bit.&lt;/P&gt;&lt;P&gt;Many thanks ed&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2024 17:46:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/notebook-create-a-csv-from-feature-service-send/m-p/1404754#M9834</guid>
      <dc:creator>EdMorris</dc:creator>
      <dc:date>2024-04-02T17:46:26Z</dc:date>
    </item>
  </channel>
</rss>

