Spaces:
Running
Running
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 | |