Odoo Help

Welcome!

This community 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.

1

How can i send email from code?

By
mirko lazzarini
on 10/9/13, 1:44 PM 2,516 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']
    body="body" 
    message_obj = self.pool.get('mail.message')
    email_to=[]
    email_to.append('a@a.it')
    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)
2

Francesco OpenCode

--Francesco OpenCode--
3608
| 5 7 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
1
zekraoui_mohamed
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 : ")

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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