Skip to content

Instantly share code, notes, and snippets.

@beledouxdenis
Last active May 16, 2019 12:47
Show Gist options
  • Save beledouxdenis/5040ba95b7094b668eb4ab24f98244ab to your computer and use it in GitHub Desktop.
Save beledouxdenis/5040ba95b7094b668eb4ab24f98244ab to your computer and use it in GitHub Desktop.
Send an email to Odoo
#!/usr/bin/env python3
import base64
import requests
from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser
from urllib.parse import urljoin
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:8069', help='URL of the Odoo server')
parser.add_argument('-d', '--dbs', dest='dbs', nargs='+', required=True, help='Odoo databases to send the email to')
args = parser.parse_args()
with open(args.eml_file, 'rb') as f:
message = base64.b64encode(f.read()).decode()
requests.post(urljoin(args.url, '/mail/receive'), json={'databases': {db: message for db in args.dbs}})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment