Show admins the email server error message when email sending fails (#2073)

* Show admins the email server error message when email sending fails
This commit is contained in:
Kevin Chung
2022-03-24 14:14:55 -04:00
committed by GitHub
parent d29102dae8
commit fc7516c91f
2 changed files with 10 additions and 2 deletions

View File

@@ -477,4 +477,10 @@ class UserEmails(Resource):
result, response = sendmail(addr=user.email, text=text)
return {"success": result}
if result is True:
return {"success": True}
else:
return (
{"success": False, "errors": {"": [response]}},
400,
)

View File

@@ -894,7 +894,9 @@ def test_api_user_send_email():
r = admin.post(
"/api/v1/users/2/email", json={"text": "email should be accepted"}
)
assert r.status_code == 200
# Email should go through but since we aren't mocking
# the server we get a Connection refused error
assert r.status_code == 400
destroy_ctfd(app)