'Process the wizard content and proceed with sending the related
email(s), rendering any template patterns on the fly if needed'

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

    SurveyUserInput = self.env['survey.user_input']
    Partner = self.env['res.partner']
    Mail = self.env['mail.mail']
    anonymous_group = self.env.ref('portal.group_anonymous', raise_if_not_found=False)
    def create_response_and_send_mail(wizard, token, partner_id, email):
        '    Create    one    mail    by    recipients    and    replace    __URL__    by    link    with    identification    token    '
        url = wizard.survey_id.public_url
        url = urlparse.urlparse(url).path[1:]
        if token:
            url = ((url + '/') + token)
        values = {'model': None, 'res_id': None, 'subject': wizard.subject, 'body': wizard.body.replace('__URL__', url), 'body_html': wizard.body.replace('__URL__', url), 'parent_id': None, 'attachment_ids': ((wizard.attachment_ids and [(6, 0, wizard.attachment_ids.ids)]) or None), 'email_from': (wizard.email_from or None), 'auto_delete': True}
        if partner_id:
            values['recipient_ids'] = [(4, partner_id)]
        else:
            values['email_to'] = email
        Mail.create(values).send()
    def create_token(wizard, partner_id, email):
        if context.get('survey_resent_token'):
            survey_user_input = SurveyUserInput.search([('survey_id', '=', wizard.survey_id.id), ('state', 'in', ['new', 'skip']), '|', ('partner_id', '=', partner_id), ('email', '=', email)], limit=1)
            if survey_user_input:
                return survey_user_input.token
        if (wizard.public != 'email_private'):
            return None
        else:
            token = uuid.uuid4().__str__()
            survey_user_input = SurveyUserInput.create({'survey_id': wizard.survey_id.id, 'deadline': wizard.date_deadline, 'date_create': fields.Datetime.now(), 'type': 'link', 'state': 'new', 'token': token, 'partner_id': partner_id, 'email': email})
            return survey_user_input.token
    for wizard in self:
        if (wizard.body.find('__URL__') < 0):
            raise UserError(_("The    content    of    the    text    don't    contain    '__URL__'.                                                                                    __URL__    is    automaticaly    converted    into    the    special    url    of    the    survey."))
        context = self.env.context
        if ((not wizard.multi_email) and (not wizard.partner_ids) and (context.get('default_partner_ids') or context.get('default_multi_email'))):
            wizard.multi_email = context.get('default_multi_email')
            wizard.partner_ids = context.get('default_partner_ids')
        emails_list = []
        if wizard.multi_email:
            emails = (set(emails_split.split(wizard.multi_email)) - set(wizard.partner_ids.mapped('email')))
            for email in emails:
                email = email.strip()
                if email_validator.match(email):
                    emails_list.append(email)
        partner_list = []
        for partner in wizard.partner_ids:
            if ((not anonymous_group) or (not partner.user_ids) or (anonymous_group not in partner.user_ids[0].groups_id)):
                partner_list.append({'id': partner.id, 'email': partner.email})
        if ((not len(emails_list)) and (not len(partner_list))):
            if ((wizard.model == 'res.partner') and wizard.res_id):
                return False
            raise UserError(_('Please    enter    at    least    one    valid    recipient.'))
        for email in emails_list:
            partner = Partner.search([('email', '=', email)], limit=1)
            token = create_token(wizard, partner.id, email)
            create_response_and_send_mail(wizard, token, partner.id, email)
        for partner in partner_list:
            token = create_token(wizard, partner['id'], partner['email'])
            create_response_and_send_mail(wizard, token, partner['id'], partner['email'])
    return {'type': 'ir.actions.act_window_close'}
