Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
10488 Переглядів

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)
Аватар
Відмінити
Найкраща відповідь

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

Найкраща відповідь

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 : ")

Аватар
Відмінити