'Sends the selected emails immediately, ignoring their current
state (mails that have already been sent should not be passed
unless they should actually be re-sent).
Emails successfully delivered are marked as \'sent\', and those
that fail to be deliver are marked as \'exception\', and the
corresponding error mail is output in the server logs.
:param bool auto_commit: whether to force a commit of the mail status
after sending each mail (meant only for scheduler processing);
should never be True during normal transactions (default: False)
:param bool raise_exception: whether to raise an exception if the
email sending process has failed
:return: True'

@api.multi
def send(self, auto_commit=False, raise_exception=False):

    IrMailServer = self.env['ir.mail_server']
    for mail_id in self.ids:
        try:
            mail = self.browse(mail_id)
            if mail.model:
                model = self.env['ir.model'].sudo().search([('model', '=', mail.model)])[0]
            else:
                model = None
            if model:
                mail = mail.with_context(model_name=model.name)
            attachments = [(a['datas_fname'], base64.b64decode(a['datas'])) for a in mail.attachment_ids.sudo().read(['datas_fname', 'datas'])]
            email_list = []
            if mail.email_to:
                email_list.append(mail.send_get_email_dict())
            for partner in mail.recipient_ids:
                email_list.append(mail.send_get_email_dict(partner=partner))
            headers = {}
            bounce_alias = self.env['ir.config_parameter'].get_param('mail.bounce.alias')
            catchall_domain = self.env['ir.config_parameter'].get_param('mail.catchall.domain')
            if (bounce_alias and catchall_domain):
                if (mail.model and mail.res_id):
                    headers['Return-Path'] = ('%s+%d-%s-%d@%s' % (bounce_alias, mail.id, mail.model, mail.res_id, catchall_domain))
                else:
                    headers['Return-Path'] = ('%s+%d@%s' % (bounce_alias, mail.id, catchall_domain))
            if mail.headers:
                try:
                    headers.update(safe_eval(mail.headers))
                except Exception:
                    pass
            mail.write({'state': 'exception', 'failure_reason': _('Error    without    exception.    Probably    due    do    sending    an    email    without    computed    recipients.')})
            mail_sent = False
            res = None
            for email in email_list:
                msg = IrMailServer.build_email(email_from=mail.email_from, email_to=email.get('email_to'), subject=mail.subject, body=email.get('body'), body_alternative=email.get('body_alternative'), email_cc=tools.email_split(mail.email_cc), reply_to=mail.reply_to, attachments=attachments, message_id=mail.message_id, references=mail.references, object_id=(mail.res_id and ('%s-%s' % (mail.res_id, mail.model))), subtype='html', subtype_alternative='plain', headers=headers)
                try:
                    res = IrMailServer.send_email(msg, mail_server_id=mail.mail_server_id.id)
                except AssertionError as error:
                    if (error.message == IrMailServer.NO_VALID_RECIPIENT):
                        _logger.info('Ignoring    invalid    recipients    for    mail.mail    %s:    %s', mail.message_id, email.get('email_to'))
                    else:
                        raise
            if res:
                mail.write({'state': 'sent', 'message_id': res, 'failure_reason': False})
                mail_sent = True
            if mail_sent:
                _logger.info('Mail    with    ID    %r    and    Message-Id    %r    successfully    sent', mail.id, mail.message_id)
            mail._postprocess_sent_message(mail_sent=mail_sent)
        except MemoryError:
            _logger.exception('MemoryError    while    processing    mail    with    ID    %r    and    Msg-Id    %r.    Consider    raising    the    --limit-memory-hard    startup    option', mail.id, mail.message_id)
            raise
        except psycopg2.Error:
            raise
        except Exception as e:
            failure_reason = tools.ustr(e)
            _logger.exception('failed    sending    mail    (id:    %s)    due    to    %s', mail.id, failure_reason)
            mail.write({'state': 'exception', 'failure_reason': failure_reason})
            mail._postprocess_sent_message(mail_sent=False)
            if raise_exception:
                if isinstance(e, AssertionError):
                    value = '.    '.join(e.args)
                    raise MailDeliveryException(_('Mail    Delivery    Failed'), value)
                raise
        if (auto_commit is True):
            self._cr.commit()
    return True
