gera commited on
Commit
b321e7a
·
1 Parent(s): a6b2676

sending emails with SendGrid

Browse files
Files changed (1) hide show
  1. app.py +19 -3
app.py CHANGED
@@ -3,14 +3,15 @@ from time import sleep
3
  from json import loads as json_loads
4
  import gradio as gr
5
  import openai
6
- import yagmail
 
7
 
8
  client = openai.OpenAI()
9
 
10
  assistant_id = "asst_NHnYFIdpvioacAJqWYMchJHI"
11
  vector_id = "vs_sqT4VRRTwkH7JPr3AT8CpoXV"
12
 
13
- def send_email(thread):
14
  mail_from = os_getenv("MAIL_FROM")
15
  mail=yagmail.SMTP(
16
  mail_from,
@@ -20,7 +21,22 @@ def send_email(thread):
20
  )
21
  mail.send(mail_from,f"New thread {thread.id}")
22
 
23
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  def chat(user_message, history, state):
25
  if (state is None) or (not state['user']):
26
  gr.Warning("You need to authenticate first")
 
3
  from json import loads as json_loads
4
  import gradio as gr
5
  import openai
6
+ from sendgrid import SendGridAPIClient
7
+ from sendgrid.helpers.mail import Mail
8
 
9
  client = openai.OpenAI()
10
 
11
  assistant_id = "asst_NHnYFIdpvioacAJqWYMchJHI"
12
  vector_id = "vs_sqT4VRRTwkH7JPr3AT8CpoXV"
13
 
14
+ def send_email_smtp(thread):
15
  mail_from = os_getenv("MAIL_FROM")
16
  mail=yagmail.SMTP(
17
  mail_from,
 
21
  )
22
  mail.send(mail_from,f"New thread {thread.id}")
23
 
24
+ def send_email(thread):
25
+ mail_from = os_getenv("MAIL_FROM")
26
+ text = f"New thread {thread.id}"
27
+ print(text)
28
+ message = Mail(
29
+ # add the email connected to your sendgrid code here
30
+ from_email=mail_from,
31
+ to_emails=mail_from,
32
+ subject=text,
33
+ html_content=text
34
+ )
35
+
36
+ sg = SendGridAPIClient(os_getenv("SENDGRID_API_KEY"))
37
+ response = sg.send(message)
38
+ print(response)
39
+
40
  def chat(user_message, history, state):
41
  if (state is None) or (not state['user']):
42
  gr.Warning("You need to authenticate first")