Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -265,7 +265,17 @@ def send_email_with_attachment(recipient_email, subject, body, attachment_path):
|
|
| 265 |
|
| 266 |
# Attach the instance 'part' to instance 'msg'
|
| 267 |
msg.attach(part)
|
|
|
|
|
|
|
| 268 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
server = smtplib.SMTP('smtp.gmail.com', 587)
|
| 270 |
server.starttls()
|
| 271 |
server.login(sender_email, sender_password)
|
|
|
|
| 265 |
|
| 266 |
# Attach the instance 'part' to instance 'msg'
|
| 267 |
msg.attach(part)
|
| 268 |
+
# Set up the SSL context
|
| 269 |
+
context = ssl.create_default_context()
|
| 270 |
|
| 271 |
+
# Send the email
|
| 272 |
+
try:
|
| 273 |
+
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server:
|
| 274 |
+
server.login(sender_email, sender_password)
|
| 275 |
+
server.sendmail(sender_email, recipient_email, msg)
|
| 276 |
+
print("Email sent successfully")
|
| 277 |
+
except Exception as e:
|
| 278 |
+
print(f"Error occurred: {str(e)}")
|
| 279 |
server = smtplib.SMTP('smtp.gmail.com', 587)
|
| 280 |
server.starttls()
|
| 281 |
server.login(sender_email, sender_password)
|