Fixed up Kingmailer API interaction

master
Raoul Snyman 2021-10-29 14:35:17 -07:00
parent a1981f23ab
commit 825c9f575a
No known key found for this signature in database
GPG Key ID: F55BCED79626AE9C
1 changed files with 6 additions and 5 deletions

View File

@ -37,13 +37,14 @@ class KingMailerHandler(object):
'data': envelope.content
}
headers = {'X-Server-API-Key': self.api_token}
response = requests.post('https://api.kingmailer.co/api/v1/send/raw', data=payload, headers=headers)
print(response)
if response.ok:
response = requests.post('https://kingmailer.org/api/v1/send/raw', json=payload, headers=headers)
resp_dict = response.json()
print(resp_dict, flush=True)
if resp_dict['status'] == 'success':
print('Message accepted', flush=True)
return '250 Message accepted for delivery'
else:
print('Could not process', flush=True)
print('{code}: {message}'.format(**resp_dict['data']), flush=True)
return '500 Could not process your message'
@ -58,5 +59,5 @@ if __name__ == '__main__':
while True:
try:
sleep(1)
except:
except Exception:
break