콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
10485 화면

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

아바타
취소