Spaces:
Running
Running
File size: 1,451 Bytes
751f3b1 ad841e1 751f3b1 a98d805 751f3b1 ad841e1 751f3b1 a98d805 751f3b1 a98d805 751f3b1 a98d805 751f3b1 a98d805 b50dddd a98d805 b50dddd a98d805 b50dddd a98d805 881b442 a98d805 b50dddd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
import requests
from utils import EMAIL, SMTP, TAG, HOST, PORT
def email_api(
content: str,
title="Runtime error detected",
header="Please fix following repo(s):",
email=EMAIL,
password=SMTP,
target=TAG,
host=HOST,
port=PORT,
):
body = f"""
<html>
<body>
<h2>{header}</h2>
{content}
</body>
</html>
"""
response = requests.get(
"http://api.mmp.cc/api/mail",
params={
"host": host,
"Port": port,
"key": password, # apikey
"email": email, # from
"mail": target, # to
"title": title, # subject
"name": "Keep Spaces Alive", # nickname
"text": body, # content
},
)
if response.status_code == 200:
result: dict = response.json()
if result.get("status") == "success":
return "Email sent successfully!"
else:
raise ConnectionError(f"Failed to send email: {result.get('message')}")
else:
raise ConnectionError(
f"Request failed with status code: {response.status_code}"
)
# UI func
def send_email(content="Test SMTP"):
status = "Success"
logs = None
try:
status = email_api(content)
logs = f"\nEmail content: {content}\n"
except Exception as e:
status = f"{e}"
print(status)
return status, logs
|