-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_mail.py
executable file
·47 lines (40 loc) · 1.65 KB
/
send_mail.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
#!/usr/bin/env python3
"""
This tool is sending mail to an Odoo instance (local or not).
Usage:
send-mail.py <eml_file>
<-d <database>>
[-u <url> default:"http://localhost:8569"]
[-U <user> default:"admin"]
[-p <password> default:"admin"]
]
Commit odoo#ab70afb is removing the previously used route '/mail/receive'
Now we use the xmlrpc function to log to the db and the odoo's method message_process of mail.thread,
the first step on received emails.
Working version:
8+
"""
import base64
import xmlrpc.client
from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser
parser = ArgumentParser(description="Send an email to Odoo databases", formatter_class=ArgumentDefaultsHelpFormatter)
parser.add_argument("eml_file", help="EML File to send")
parser.add_argument("-u", "--url", dest="url", default="http://localhost:8569", help="URL of the Odoo server")
parser.add_argument("-d", "--db", dest="db", required=True, help="Odoo database to send the email to")
parser.add_argument("-U", "--user", dest="username", default="admin", help="Login to connect with")
parser.add_argument("-p", "--password", dest="password", default="admin", help="Password to connect with")
args = parser.parse_args()
common = xmlrpc.client.ServerProxy("{}/xmlrpc/2/common".format(args.url))
uid = common.authenticate(args.db, args.username, args.password, {})
models = xmlrpc.client.ServerProxy("{}/xmlrpc/2/object".format(args.url))
with open(args.eml_file, "rb") as f:
message = f.read()
# message = base64.b64encode(f.read()).decode()
models.execute_kw(
args.db,
uid,
args.password,
"mail.thread",
"message_process",
[False, message],
)