'Generates a new mail message for the given template and record,
and schedules it for delivery through the ``mail`` module\'s scheduler.
:param int res_id: id of the record to render the template with
(model is taken from the template)
:param bool force_send: if True, the generated mail.message is
immediately sent after being created, as if the scheduler
was executed for this message only.
:param dict email_values: if set, the generated mail.message is
updated with given values dict
:returns: id of the mail.message that was created'

@api.multi
def send_mail(self, res_id, force_send=False, raise_exception=False, email_values=None):

    self.ensure_one()
    Mail = self.env['mail.mail']
    Attachment = self.env['ir.attachment']
    values = self.generate_email(res_id)
    values['recipient_ids'] = [(4, pid) for pid in values.get('partner_ids', list())]
    values.update((email_values or {}))
    attachment_ids = values.pop('attachment_ids', [])
    attachments = values.pop('attachments', [])
    if (('email_from' in values) and (not values.get('email_from'))):
        values.pop('email_from')
    mail = Mail.create(values)
    for attachment in attachments:
        attachment_data = {'name': attachment[0], 'datas_fname': attachment[0], 'datas': attachment[1], 'type': 'binary', 'res_model': 'mail.message', 'res_id': mail.mail_message_id.id}
        attachment_ids.append(Attachment.create(attachment_data).id)
    if attachment_ids:
        values['attachment_ids'] = [(6, 0, attachment_ids)]
        mail.write({'attachment_ids': [(6, 0, attachment_ids)]})
    if force_send:
        mail.send(raise_exception=raise_exception)
    return mail.id
