JBHF commited on
Commit
6a0b10f
·
verified ·
1 Parent(s): 634b981

Update app.py

Browse files

UPDATE 23-10-2024: SEND EMAIL USING SENDGRID API

Files changed (1) hide show
  1. app.py +56 -2
app.py CHANGED
@@ -1,4 +1,38 @@
1
- # NonToxicGlazeAdvisor_Chat_with_Docs_Groq_Edition_1 - app.py - 16-06-2024
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  # STREAMLIT:
4
  # https://www.datacamp.com/tutorial/streamlit:
@@ -1224,8 +1258,28 @@ with tab1:
1224
  st.write(st.session_state.messages)
1225
  st.write("--------------------------------")
1226
 
1227
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1228
 
 
 
 
 
1229
  st.write("---------------------------------")
1230
 
1231
 
 
1
+ # NonToxicGlazeAdvisor_Chat_with_Docs_Groq_Edition_1 - app.py - 23-10-2024 (derived from 16-06-2024 version)
2
+ #
3
+ # ADDED 23-10-2024:
4
+ # sendgrid Python lib - to send emails via the sendgrid API
5
+ # ZIE :
6
+ # SEND EMAIL VIA SENDGRID API IN PYTHON -23-10-2024
7
+ # COLAB
8
+ # jfhmbours
9
+ # https://colab.research.google.com/drive/1UeCtxNkmOGikMLFpxtQpo4wxld7c8mE1?authuser=0#scrollTo=WLhfUTY2p1kC
10
+ # SEND EMAIL VIA SENDGRID API-COLAB-CPU-PYTHON3-jfhmboyrs.ipynb
11
+ #
12
+ # EXAMPLE TESTED (!) CODE:
13
+ # from sendgrid import SendGridAPIClient
14
+ # from sendgrid.helpers.mail import Mail
15
+ # message = Mail(
16
+ # from_email='tvscitechtalk@gmail.com',
17
+ # to_emails='allecomputerhulp@gmail.com', # to_emails='tvscitechtalk@gmail.com',
18
+ # subject='Sending with Twilio SendGrid is Fun',
19
+ # html_content='<strong>JB: DEZE EMAILVERSTUURD VANUIT COLAB VAN tvscitechtalk@gmail.com NAAR allecomputerhulp@gmail.com OP 23-10-2024 om 16:51 CET</strong>')
20
+ #
21
+ #try:
22
+ # # sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) # ORIGINAL
23
+ # sg = sendgrid.SendGridAPIClient(api_key=userdata.get('SENDGRID_API_KEY')) # JB COLAB
24
+ # response = sg.send(message)
25
+ # print(response.status_code)
26
+ # print(response.body)
27
+ # print(response.headers)
28
+ #except Exception as e:
29
+ # print(e.message)
30
+ from sendgrid import SendGridAPIClient
31
+ from sendgrid.helpers.mail import Mail
32
+
33
+
34
+
35
+
36
 
37
  # STREAMLIT:
38
  # https://www.datacamp.com/tutorial/streamlit:
 
1258
  st.write(st.session_state.messages)
1259
  st.write("--------------------------------")
1260
 
1261
+ # START UPDATE 23-10-2024: SEND EMAIL USING SENDGRID API
1262
+ message = Mail(
1263
+ from_email='tvscitechtalk@gmail.com',
1264
+ to_emails='allecomputerhulp@gmail.com', # to_emails='tvscitechtalk@gmail.com',
1265
+ subject='Sending email from source NONTOXICGLAZEADVISOR APP ON HF SPACES with Twilio SendGrid',
1266
+ html_content='<strong>JB: DEZE EMAIL IS VERSTUURD VANUITDE NONTOXICGLAZEADVISOR APP ON HF SPACES VAN tvscitechtalk@gmail.com NAAR allecomputerhulp@gmail.com OP 23-10-2024 om 16:51 CET</strong>')
1267
+
1268
+
1269
+ try:
1270
+ sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) # ORIGINAL
1271
+ # sg = sendgrid.SendGridAPIClient(api_key=userdata.get('SENDGRID_API_KEY')) # JB COLAB
1272
+ response = sg.send(message)
1273
+ print(response.status_code)
1274
+ print(response.body)
1275
+ print(response.headers)
1276
+ except Exception as e:
1277
+ print(e.message)
1278
 
1279
+ # END UPDATE 23-10-2024: SEND EMAIL USING SENDGRID API
1280
+
1281
+
1282
+
1283
  st.write("---------------------------------")
1284
 
1285