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

Email Send in Odoo?

By
wizardz
on 10/30/15, 5:34 AM 650 views

Hi,

I'm making a simple modul that show me a html form with a textfield. Now I wanted to know how I can send an email to a adress after pushing the submit button in the form?

Is there any example code for moduls?

0
wizardz
On 11/2/15, 3:17 AM

this is the python code:

# -*- coding: utf-8 -*-

from openerp import models, fields, api


def send_mail_example(self,cr,uid,ids,odoo_record,context=None):
ir_mail_server = self.pool.get('ir.mail_server')
title = "Your e-mail title"
message = "This is the concent from your e-mail. An example from a field inside the e-mail: " + odoo_record.odoo_dns_url + "\n\nWith kind regards,\nYenthe"
#Structure mail function: def build_email(self, email_from, email_to, subject, body, email_cc=None, email_bcc=None, reply_to=False,
msg = ir_mail_server.build_email("test23.test@gmx.ch", ["test23.test@gmx.ch"], title, message,["test23.test@gmx.chh"],[],"test23.test@gmx.ch")
ir_mail_server.send_email(cr, uid, msg)

thanks for your help 

What is wrong. When I click the button nothing happen. 

0

Yenthe

--Yenthe--
6716
| 7 7 8
Turnhout, Belgium
--Yenthe--

My Odoo blog: http://www.odoo.yenthevg.com/

My Twitter: https://twitter.com/Yenthe666

Yenthe
On 10/30/15, 7:03 AM

Hi diezcode,

There are quite some options and methods for this but I'll give you an example.

def send_mail_example(self,cr,uid,ids,odoo_record,context=None):
ir_mail_server = self.pool.get('ir.mail_server')
title = "Your e-mail title"
message = "This is the concent from your e-mail. An example from a field inside the e-mail: " + odoo_record.odoo_dns_url + "\n\nWith kind regards,\nYenthe"
#Structure mail function: def build_email(self, email_from, email_to, subject, body, email_cc=None, email_bcc=None, reply_to=False,
msg = ir_mail_server.build_email("emailfrom@gmail.com", ["emailto@gmail.com"], title, message,["example@gmail.com"],[],"example@gmail.com")
ir_mail_server.send_email(cr, uid, msg)

With this example you could do about everything you need. Other options to use can be found under addons/mail/views/mail_mail.py in the official Odoo code, which contains a lot of e-mail functions.
You can trigger this Python function just like any other method with a button. I have an example module which explains how buttons work here: https://github.com/Yenthe666/Odoo_Samples/tree/master/button_action_demo

Update: and an example with a button inside the view (not in the topbar):

<button name="send_mail_example" type="object" string="Send E-mail"/>

Yenthe

How can I connect with a submit button from a normal form in a xml.-file?

wizardz
on 10/30/15, 9:45 AM

Added a button sample that is inside the form and not in the top bar.

Yenthe
on 10/30/15, 10:00 AM

nothing happend, I have a send_mail_example.py with this def send_mail_example code inside, what I need to do that this works?

wizardz
on 11/2/15, 2:36 AM

Hard to tell from this side what is missing or what is not. Place a logging statement inside your Python function and see if that goes off. If it doesn't it means you never reach the Python function. Make sure the name of the button and the name of the Python function (the function, not the file) are exactly the same. If that all doesn't fix it then add your code in your question please. :)

Yenthe
on 11/2/15, 2:58 AM

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/30/15, 5:34 AM
Seen: 650 times
Last updated: 11/5/15, 3:18 AM