'Sends an email directly (no queuing).
No retries are done, the caller should handle MailDeliveryException in order to ensure that
the mail is never lost.
If the mail_server_id is provided, sends using this mail server, ignoring other smtp_* arguments.
If mail_server_id is None and smtp_server is None, use the default mail server (highest priority).
If mail_server_id is None and smtp_server is not None, use the provided smtp_* arguments.
If both mail_server_id and smtp_server are None, look for an \'smtp_server\' value in server config,
and fails if not found.
:param message: the email.message.Message to send. The envelope sender will be extracted from the
``Return-Path`` (if present), or will be set to the default bounce address.
The envelope recipients will be extracted from the combined list of ``To``,
``CC`` and ``BCC`` headers.
:param mail_server_id: optional id of ir.mail_server to use for sending. overrides other smtp_* arguments.
:param smtp_server: optional hostname of SMTP server to use
:param smtp_encryption: optional TLS mode, one of \'none\', \'starttls\' or \'ssl\' (see ir.mail_server fields for explanation)
:param smtp_port: optional SMTP port, if mail_server_id is not passed
:param smtp_user: optional SMTP user, if mail_server_id is not passed
:param smtp_password: optional SMTP password to use, if mail_server_id is not passed
:param smtp_debug: optional SMTP debug flag, if mail_server_id is not passed
:return: the Message-ID of the message that was just sent, if successfully sent, otherwise raises
MailDeliveryException and logs root cause.'

@api.model
def send_email(self, message, mail_server_id=None, smtp_server=None, smtp_port=None, smtp_user=None, smtp_password=None, smtp_encryption=None, smtp_debug=False):

    smtp_from = (message['Return-Path'] or self._get_default_bounce_address() or message['From'])
    assert smtp_from, 'The    Return-Path    or    From    header    is    required    for    any    outbound    email'
    from_rfc2822 = extract_rfc2822_addresses(smtp_from)
    assert from_rfc2822, ("Malformed    'Return-Path'    or    'From'    address:    %r    -    It    should    contain    one    valid    plain    ASCII    email" % smtp_from)
    smtp_from = from_rfc2822[(-1)]
    email_to = message['To']
    email_cc = message['Cc']
    email_bcc = message['Bcc']
    smtp_to_list = filter(None, tools.flatten(map(extract_rfc2822_addresses, [email_to, email_cc, email_bcc])))
    assert smtp_to_list, self.NO_VALID_RECIPIENT
    x_forge_to = message['X-Forge-To']
    if x_forge_to:
        del message['X-Forge-To']
        del message['To']
        message['To'] = x_forge_to
    if getattr(threading.currentThread(), 'testing', False):
        _test_logger.info('skip    sending    email    in    test    mode')
        return message['Message-Id']
    mail_server = None
    if mail_server_id:
        mail_server = self.sudo().browse(mail_server_id)
    elif (not smtp_server):
        mail_server = self.sudo().search([], order='sequence', limit=1)
    if mail_server:
        smtp_server = mail_server.smtp_host
        smtp_user = mail_server.smtp_user
        smtp_password = mail_server.smtp_pass
        smtp_port = mail_server.smtp_port
        smtp_encryption = mail_server.smtp_encryption
        smtp_debug = (smtp_debug or mail_server.smtp_debug)
    else:
        smtp_server = (smtp_server or tools.config.get('smtp_server'))
        smtp_port = (tools.config.get('smtp_port', 25) if (smtp_port is None) else smtp_port)
        smtp_user = (smtp_user or tools.config.get('smtp_user'))
        smtp_password = (smtp_password or tools.config.get('smtp_password'))
        if ((smtp_encryption is None) and tools.config.get('smtp_ssl')):
            smtp_encryption = 'starttls'
    if (not smtp_server):
        raise UserError(((_('Missing    SMTP    Server') + '\n') + _('Please    define    at    least    one    SMTP    server,    or    provide    the    SMTP    parameters    explicitly.')))
    try:
        message_id = message['Message-Id']
        if smtp_server.startswith('maildir:/'):
            from mailbox import Maildir
            maildir_path = smtp_server[8:]
            mdir = Maildir(maildir_path, factory=None, create=True)
            mdir.add(message.as_string(True))
            return message_id
        smtp = None
        try:
            smtp = self.connect(smtp_server, smtp_port, smtp_user, smtp_password, (smtp_encryption or False), smtp_debug)
            smtp.sendmail(smtp_from, smtp_to_list, message.as_string())
        finally:
            if (smtp is not None):
                smtp.quit()
    except Exception as e:
        params = (ustr(smtp_server), e.__class__.__name__, ustr(e))
        msg = (_("Mail    delivery    failed    via    SMTP    server    '%s'.\n%s:    %s") % params)
        _logger.info(msg)
        raise MailDeliveryException(_('Mail    Delivery    Failed'), msg)
    return message_id
