This repository has been archived by the owner on Apr 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
send.py
executable file
·65 lines (63 loc) · 1.64 KB
/
send.py
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
63
64
65
#! /usr/bin/env python3
import argparse
import requests
def main():
parser = argparse.ArgumentParser(description="Send a test message using the Postal HTTP API")
parser.add_argument(
"-t", "--to",
nargs="+", required=True,
help="Email recipient. This option can be repeated multiple times"
)
parser.add_argument(
"-f", "--from",
dest="sender", required=True,
help="Email sender"
)
parser.add_argument(
"-s", "--subject",
default="Hello world",
help="Email subject"
)
parser.add_argument(
"-b", "--plain-body",
default="",
help="Email plain body"
)
parser.add_argument(
"-B", "--html-body",
default="",
help="Email html body"
)
parser.add_argument(
"-k", "--key",
required=True,
help="API key"
)
parser.add_argument(
"-H", "--host",
default="http://localhost",
help="Postal host"
)
parser.add_argument(
"-p", "--port",
type=int, default=80,
help="Postal port"
)
args = parser.parse_args()
response = requests.post(
"{}:{}/api/v1/send/message".format(args.host, args.port),
json={
"to": args.to,
"from": args.sender,
"subject": args.subject,
"plain_body": args.plain_body,
"html_body": args.html_body,
},
headers={
"X-Server-API-Key": args.key,
}
)
print("Response code:", response.status_code)
print("Response body:", response.content.decode())
if __name__ == "__main__":
main()