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) |