deta/deta-python

Redundant send_email

leits opened this issue ยท 2 comments

leits commented

Hi, Deta team!
Looks like I found the code for your internal needs in the client ๐Ÿ˜…

def send_email(to, subject, message, charset="UTF-8"):
pid = os.getenv("AWS_LAMBDA_FUNCTION_NAME")
url = os.getenv("DETA_MAILER_URL")
api_key = os.getenv("DETA_PROJECT_KEY")
endpoint = f"{url}/mail/{pid}"
to = to if type(to) == list else [to]
data = {
"to": to,
"subject": subject,
"message": message,
"charset": charset,
}
headers = {"X-API-Key": api_key}
req = urllib.request.Request(endpoint, json.dumps(data).encode("utf-8"), headers)
try:
resp = urllib.request.urlopen(req)
if resp.getcode() != 200:
raise Exception(resp.read().decode("utf-8"))
except urllib.error.URLError as e:
raise Exception(e.reason)

xeust commented

Hi there @leits,

This code is actually for our upcoming email service ๐Ÿคซ

leits commented

Spoiler ๐Ÿ˜„