Odoo Help


send mail from controller in odoov9

on 1/21/16, 5:07 AM 1,500 views


i am using odoo v9 in ubuntu 12.04,i created one custom module and from controller i write code for form submission after submit form i want to send mail to res.partner from odoo

my controller.py is

from openerp import http

from openerp.http import Controller, route, request

from openerp.addons.website.models.website import slug

from werkzeug.utils import redirect

from wtforms import Form, StringField, TextAreaField, validators, SelectField, DateField

class CreateMarraige(http.Controller):

    @http.route('/marraige/new/', website=True)

    def new(self, cr, uid, ids, context=None, **form_data):

        form = MarraigeForm(request.httprequest.form)

        if request.httprequest.method == 'POST' and form.validate():

             marraige = http.request.env['consulate.marraige']

             customer = http.request.env['res.partner']

            cust = customer.create({

            'name' : form_data.get('nm_of_husband', ''),

            'birthdate': form_data.get('birth_dt_hus', ''),



                 'father_nm_of_husband': form_data.get('father_nm_of_husband', ''),

                 'mother_nm_of_husband': form_data.get('mother_nm_of_husband', ''),

                 'occupation_of_hus': form_data.get('occupation_of_hus', ''),

                 'age_of_hus': form_data.get('age_of_hus', ''),

                 'birth_place_hus': form_data.get('birth_place_hus', ''),

                 'nm_of_wife': form_data.get('nm_of_wife', ''),

                 'father_nm_of_wife': form_data.get('father_nm_of_wife', ''),

                 'mother_nm_of_wife': form_data.get('mother_nm_of_wife', ''),

                 'occupation_of_wife': form_data.get('occupation_of_wife', ''),

                 'age_of_wife': form_data.get('age_of_wife', ''),

                 'birth_dt_wife': form_data.get('birth_dt_wife', ''),

                 'birth_place_wife': form_data.get('birth_place_wife', ''),

                 'rep_of_husband': form_data.get('rep_of_husband', ''),

                 'rep_of_wife': form_data.get('rep_of_wife', ''),

                 'witness_of_hus': form_data.get('witness_of_hus', ''),

                 'witness_of_wife': form_data.get('witness_of_wife', ''),

                 'registrar': form_data.get('registrar', ''),

                 'cert_issued_by': form_data.get('cert_issued_by', ''),

                 'partner_id': cust.id,


            message = ("Hello %s \n Below Prurchase Order is Delay Today: \n Supplier Name : %s \n Purchase Order Refereance :             %s \n Order Date : %s \n Delivery Date : %s \n Product Names : %s \n\n")


             vals = {'state': 'outgoing',

                         'subject': 'CVs',

                         'body_html': '<pre>%s</pre>' % message,

                         'email_to': rec.job_id.partner_id.email,

                         'email_from': 'vrstest123@gmail.com',


                 email_ids.append(self.pool.get('mail.mail').create(cr, uid, vals, context=context))

                 if email_ids:

                     self.pool.get('mail.mail').send(cr, uid, email_ids, context=context)


            return redirect("/marraige_success/")

            return request.render('marraige_certificate.marraige_create', {'form': form})

after submit form it return error like


'CreateMarraige' object has no attribute 'pool'


please help how can i solve this error and send mail from controller

Nilesh Sheliya
On 1/21/16, 7:15 AM

Please use http.request.env['mail.mail'] instead of self.pool.get('mail.mail'). Your statement is like,

total_emails = http.request.env['mail.mail'].browse()

total_emails = total_emails + http.request.env['mail.mail'].create(vals)


hi i tried your solution error remove but still mail no send i set val is vals = {'state': 'outgoing', 'subject': 'Testing', 'body_html': '

' % message, 'email_to': 'kartik@vrsweb.in', 'email_from': 'vrstest123@gmail.com', #'attachment_ids': [(6, 0, attachment_ids)], } total_emails = http.request.env['mail.mail'].browse() total_emails = total_emails + http.request.env['mail.mail'].create(vals) total_emails.send()
on 1/21/16, 7:52 AM

hi i want to use another email id so how can i set password,port and all details for sending mail

on 1/21/16, 8:17 AM

can you please explain that what we pass in "vals" currently my vals is look like vals = {'state': 'outgoing', 'subject': 'Testing', 'body_html': '

' % message, 'email_to': 'kartik@vrsweb.in', 'email_from': 'vrstest123@gmail.com', }
on 1/25/16, 2:09 AM

Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
| 6 7 8
Rajkot, India
--Emipro Technologies Pvt. Ltd.--

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions.


Since establishment, our business has span across 11 countries of the world. Our customers are companies of all sizes ranging from start-ups to large enterprises, who realize that they need a professional business solutions to generate revenue streams, establish proper communication channels or streamline business operations. Standing with strong determination of customer satisfaction, observing each minute detail of their business processes, providing proper guidance and moving forth to develop product accordingly adds our value and reliability among our customers. 


We are blessed with efficient, passionate & eclectic young developers who have come across almost all kinds of business profiles, working with full dedication, applying creativity & new features in existing modules and completing customer's projects successfully on predefined target. Our in-depth knowledge while giving business solutions in Odoo allows us to offer following services to our customers :


  • Consulting
  • Installation, Configuration & Customization
  • Training & Support
  • Maintenance
  • Upgradation
  • Documentation
  • Crafting community modules
  • Drafting videos on demand
  • Smart Apps development

We will be :) to welcome you @ www.emiprotechnologies.com to solve any kind of your business needs around Odoo. However we are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech

Emipro Technologies Pvt. Ltd.
On 1/21/16, 6:26 AM

You will not able to use "self.pool" in controller, to access the models. Try following:

obj_model = request.env['model.name']

Hope this helps !!.

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: 1/21/16, 5:07 AM
Seen: 1500 times
Last updated: 1/21/16, 7:15 AM