This question has been flagged

Hello!

I try to send a notification and e-mail to specified users, or groups, when i click a button. I've already gotten notifications work, but my e-mails are not sent, I do not know what I'm doing wrong. I've tried also send a URL for the user to directly access, but I can't get the browser URL, instead of leaving written manually.

This is my code.

# Send E-Mail
def enviar_email(self, cr, uid, user_ids, text=None, context=None):
    osv.logging.log(100, "[Alca] enviar_email:hr_expense:hr_expense_nervia")
    mail_compose = self.pool.get('mail.compose.message')

    for user in user_ids:
        compose_id = mail_compose.create(cr, user,
            {'subject': 'Asunto', 'body': 'Este es mi mensaje', 'partner_ids': user_ids},
            {'default_composition_mode': 'mass_mail', 'default_starred': True})
        mail_compose.send_mail(cr, user, [compose_id])

# Send Notification
def send_notificacion(self, cr, uid, ids, text=None, context=None):
    osv.logging.log(100, "[Alca] send_notificacion:hr_expense:hr_expense_nervia")

    if context == None:
        context = {}

    context.update({'default_starred': True})

    for record in self.browse(cr, uid, ids, context=context):
        notify_to = []
        notify_to = self._get_autorized_contables(cr, uid, context)
        notify_to.append(record.employee_id.user_id.id)
        notify_to.append(int(record.autorizador))

        text = text + (" <a href='http://192.168.10.227:7069/?db=desarrollo#id=%s&view_type=form&model=hr.expense.expense'>Procesar</a>" % (record.id))

        self.enviar_email(cr, uid, notify_to, text, context)

        # Loguea una nota en la nota de gastos
        self.message_post(cr, uid, [record.id], _(text), context=context)
        # Suscribe a los usuarios y les manda una notificacion a la bandeja de entrada
        self.message_subscribe_users(cr, uid, [record.id], user_ids=notify_to, context=context)
Avatar
Discard
Author

I resolve the question about how to send email. :)

    from openerp import tools
    # Send E-Mail
    def enviar_email(self, cr, uid, user_ids, asunto = None, text=None, context=None):
            mUsr = self.pool.get("res.users")
            for usr in user_ids:
                user = mUsr.browse(cr, uid, usr)
                if user.email:
                    subject = "[OpenERP] Notificacion: "+str(asunto)
                    body = text
                    <a href="mailto:tools.email_send('noreply@openerp.com'">tools.email_send('noreply@openerp.com'</a>, [user.email, ], subject, body)