Amirizaniani commited on
Commit
4f03c9a
·
verified ·
1 Parent(s): a411997

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -28
app.py CHANGED
@@ -147,7 +147,6 @@ def answer_question(prompt):
147
  return generated_answer
148
 
149
 
150
-
151
  def process_inputs(llm, file, relevance, diversity, email):
152
  # Check if file is uploaded
153
  if file is not None:
@@ -170,46 +169,38 @@ def process_inputs(llm, file, relevance, diversity, email):
170
  csv_file = "questions.csv"
171
  df.to_csv(csv_file, index=False)
172
 
173
- # Check network connectivity to SendGrid
174
  try:
175
- socket.create_connection(("smtp.sendgrid.net", 587), timeout=10)
176
  except OSError:
177
  return "Network is unreachable. Unable to send email."
178
 
179
- # Email the CSV file using SendGrid
180
  sender_email = "[email protected]"
 
181
  receiver_email = email
182
  subject = "Your Submitted Questions"
183
  body = "Thank you for your submission. Please find attached the CSV file containing your questions."
184
 
185
- message = Mail(
186
- from_email=sender_email,
187
- to_emails=receiver_email,
188
- subject=subject,
189
- html_content=body
190
- )
191
-
192
- with open(csv_file, "rb") as f:
193
- data = f.read()
194
- encoded_file = base64.b64encode(data).decode()
195
-
196
- attached_file = Attachment(
197
- FileContent(encoded_file),
198
- FileName('questions.csv'),
199
- FileType('text/csv'),
200
- Disposition('attachment')
201
- )
202
 
203
- message.attachment = attached_file
 
 
 
 
 
204
 
205
  try:
206
- sg = SendGridAPIClient(os.environ.get('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'))
207
- response = sg.send(message)
208
- print(response.status_code)
209
- print(response.body)
210
- print(response.headers)
211
  except Exception as e:
212
- print(e.message)
213
  return f"Failed to send email: {e}"
214
 
215
  return "Submitted"
 
147
  return generated_answer
148
 
149
 
 
150
  def process_inputs(llm, file, relevance, diversity, email):
151
  # Check if file is uploaded
152
  if file is not None:
 
169
  csv_file = "questions.csv"
170
  df.to_csv(csv_file, index=False)
171
 
172
+ # Check network connectivity to the custom port
173
  try:
174
+ socket.create_connection(("your.relay.server", 25), timeout=10) # Replace with your relay server and port
175
  except OSError:
176
  return "Network is unreachable. Unable to send email."
177
 
178
+ # Email the CSV file
179
  sender_email = "[email protected]"
180
+ sender_password = "opri fcxx crkh bvfj"
181
  receiver_email = email
182
  subject = "Your Submitted Questions"
183
  body = "Thank you for your submission. Please find attached the CSV file containing your questions."
184
 
185
+ message = MIMEMultipart()
186
+ message['From'] = sender_email
187
+ message['To'] = receiver_email
188
+ message['Subject'] = subject
189
+ message.attach(MIMEText(body, 'plain'))
 
 
 
 
 
 
 
 
 
 
 
 
190
 
191
+ with open(csv_file, "rb") as attachment:
192
+ part = MIMEBase('application', 'octet-stream')
193
+ part.set_payload(attachment.read())
194
+ encoders.encode_base64(part)
195
+ part.add_header('Content-Disposition', f"attachment; filename= questions.csv")
196
+ message.attach(part)
197
 
198
  try:
199
+ with smtplib.SMTP('your.relay.server', 25) as server: # Use your relay server and custom port
200
+ server.starttls() # Upgrade the connection to a secure encrypted SSL/TLS connection
201
+ server.login(sender_email, sender_password)
202
+ server.sendmail(sender_email, receiver_email, message.as_string())
 
203
  except Exception as e:
 
204
  return f"Failed to send email: {e}"
205
 
206
  return "Submitted"