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.

0

How to create email template using python

By
pza
on 7/29/14, 11:58 PM 6,142 views

Hello,

    I want to create a mail template in python as i need some dynamic values and send mail using that template. How can i create a mail.template from python side?

 

Regards,

It will be good if you can explain the scenario, what exactly you want to achieve.

Mantavya Gajjar (mga)
on 7/30/14, 12:08 AM
2

Serpent Consulting Services Pvt. Ltd.

--Serpent Consulting Services Pvt. Ltd.--
4341
| 6 6 8
Gandhinagar, India
--Serpent Consulting Services Pvt. Ltd.--

Serpent Consulting Services Pvt. Ltd. Your Odoo/OpenERP Solution, just an email away!

Serpent Consulting Services Pvt. Ltd.
On 7/30/14, 2:51 AM

Hello,

You have to use create method of email.template object.

For e.g. if you want to create a template for sale order and want to send mail using that template than you have to write particular code inside your method

template_obj = self.pool.get('email.template')
group_model_id = self.pool.get('ir.model').search(cr, uid, [('model', '=', 'sale.order')])[0]
body_html = '''Message whatever you want to send'''
template_data = {
    'model_id': group_model_id,
    'name': 'Template Name',
    'subject' : 'Subject for your email',
    'body_html': body_html,
    'email_from' : '${object.user_id.email}',
    'email_to' : '${object.partner_id.email}',
}

template_id = template_obj.create(cr, uid, template_data, context=context)
template_obj.send_mail(cr, uid, template_id, ids[0], force_send=True, context=context)

It will send a mail with given values in dictionary.

Thanks.

sir, I have created a email template via openerp and added a context action... it works fine... but i want my button

Anand
on 11/29/14, 2:49 AM

Button should do the same action.... send emaill i think self.pool.get('email.template').send_mail(cr, uid,9,context[1], context,True, context=context) this may do.. but givew error.. please help me..

Anand
on 11/29/14, 2:54 AM
0
Mariusz Mizgier
On 7/30/14, 1:22 AM

As far as I understood that question, you want to create a new mail, which will take some values from the current model and use that in HTML mail sent to the partner. You can easily do that, just go to the module base_calendar and look for example for _links_get function and its usage through the code.

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

2 follower(s)

Stats

Asked: 7/29/14, 11:58 PM
Seen: 6142 times
Last updated: 3/16/15, 8:10 AM