Odoo Help


How can i send email from code?

mirko lazzarini
on 10/9/13, 1:44 PM 3,839 views

I'm trying to send email from code like this in a custom addon when i push a button on a Purchase Order form, there is only a problem... body result empty... i can't undestand where is the error... Anyone can help me?

def req_aut(self, cr, uid, ids, context=None):
    pur_ord = self.read(cr, uid, ids, ['name'], context=context)[0]
    subject="subject: "+ pur_ord['name']
    message_obj = self.pool.get('mail.message')
    msg_vals = {
        'subject': subject,
        'date': time.strftime('%Y-%m-%d %H:%M:%S'),
        'user_id': uid,
        'body_text': False,
        'body_html': body,
        'email_from': 'appo@appo.it',
        'email_to': email_to,
        'subtype': 'html',
        'state': 'outgoing',
    msg_id = message_obj.create(cr, uid, msg_vals, context)

Francesco OpenCode

--Francesco OpenCode--

| 6 8 9
Grottaglie, Italy
--Francesco OpenCode--

Italian Odoo (OpenERP) Modules Developer LINKEDIN: http://www.linkedin.com/in/francescoapruzzese

Francesco OpenCode
On 10/9/13, 1:54 PM

Here you can find a function that I use (in the cron) to send email. Use it as example to understand how to send email

Done but 'body' and 'email to' result empty

mirko lazzarini
on 10/10/13, 1:03 PM
On 10/9/13, 2:16 PM

import email, mimetypes from email.Header import decode_header from email.MIMEText import MIMEText import email_template

#Send mail sans queue ir_mail_server = self.pool.get('ir.mail_server') msg = ir_mail_server.build_email("test_msg <e>", ["test@gmail.com"], "My subject", my message") ir_mail_server.send_email(cr, uid, msg)

#Send mail template_inst = self.pool.get('email.template').search(cr,uid,[('name','=',' template name')]) if(template_inst): self.pool.get('email.template').send_mail(cr,uid,template_inst[0],ids[0],False,context) else: logger.error("Email Template not Found : ")

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 10/9/13, 1:44 PM
Seen: 3839 times
Last updated: 3/16/15, 8:10 AM