Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Managament
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Producție
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

Unable to send emails

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
emailmailtemplatev18CommunityEdition
2 Răspunsuri
1337 Vizualizări
Imagine profil
Shreya Doodipala

I'm using the following code to send an email notification whenever a new record is created.

@api.model
    def create(self,vals):
        record = super().create(vals)
        def send_email_after_commit():
            new_record = self.browse(record.id)
            new_record.send_custom_email()

        self.env.cr.postcommit.add(send_email_after_commit)
        return record
   
    def send_custom_email(self):
        template = self.env.ref('crm.email_template_added_to_opp')

        # Only send to head if not the same as creator
        if self.write_uid.id != self.head_id.id and self.head_id.partner_id:
            recipient_ids = [self.head_id.partner_id.id]
            email_values = {'recipient_ids': [(6, 0, recipient_ids)], }
            template.send_mail(self.id, email_values=email_values)

If I use force_send=True, the email is sent. However, if I don't set it, the email is never sent.

My email cron job is working properly as I have other emails that are sent without a problem.

Email Template

<record id="email_template_added_to_opp" model="mail.template">
            <field name="name">Added to Opportunity Notification</field>
            <field name="model_id" ref="crm.model_name"/>
            <field name="email_from">testam1sales@gmail.com</field>
            <field name="subject">Added to New Opportunity: {{object.lead_id.name}}</field>
            <field name="body_html" type="html"> <div>
                <p>Hello <t t-out='object.bu_head_id.name' />,</p>
                <p>You have been added to a new opportunity <strong> <t t-out="object.lead_id.name" /> </strong>. <br/>
                <a t-attf-href="#{object.lead_id.get_base_url()}/web#id=#{object.lead_id.id}&amp;model=crm.lead&amp;view_type=form"><span style="background-color:green; color:white; padding:4px 10px;">Open <t t-out="object.lead_id.name" /></span></a></p>
                <p><strong>Customer:</strong> <t t-out="object.lead_id.partner_id.name" /> <br/>
                <strong>Salesperson:</strong> <t t-out="object.lead_id.user_id.name" /> <br/>

                <p>Thanks,<br/>
                CRM System</p>
            </div> </field>
        </record>

Odoo v18 Community Edition

0
Imagine profil
Abandonează
Imagine profil
John
Cel mai bun răspuns

send_mail(..., force_send=False) creates a mail.mail record, but Odoo’s mail queue will only send it correctly if it’s fully committed and not in a broken state. Using post-commit + force_send=True is the most reliable for real-time delivery


@api.model

def create(self, vals):

    record = super().create(vals)


    def send_email_after_commit():

        template = self.env.ref('crm.email_template_added_to_opp')

        if self.env.cr.postcommit.add(send_email_after_commit)

    return record


0
Imagine profil
Abandonează
Imagine profil
D Enterprise
Cel mai bun răspuns

Hii,
Update your Python method:

def send_custom_email(self):

    template = self.env.ref('crm.email_template_added_to_opp', raise_if_not_found=False)

    if not template:

        return


    if self.id, email_values=email_values, force_send=False)


Fix your Email Template XML:
<record id="email_template_added_to_opp" model="mail.template">

    <field name="name">Added to Opportunity Notification</field>

    <field name="model_id" ref="your_module.model_your_model"/>  

    <field name="email_from">testam1sales@gmail.com</field>

    <field name="subject">New Opportunity: ${object.lead_id.name}</field>

    <field name="body_html" type="html">

        <div>Hello ${object.bu_head_id.name}, you've been added to ${object.lead_id.name}.</div>

    </field>

    <field name="auto_delete" eval="False"/>  

</record>

To find correct model ID:

  • Go to Settings > Technical > Models
  • Copy the XML ID for your model, like: your_module.model_your_model
Ensure Email Cron is Active:
  • Settings > Technical > Scheduled Actions
  • Find "Mail: Email Queue Manager"
  • Make sure it is enabled and runs every 1–5 minutes.

i hope it is usefull

0
Imagine profil
Abandonează
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
Modify Email Notifications
email notifications v18 CommunityEdition EmailNotification
Imagine profil
Imagine profil
1
iun. 25
2401
Is it possible to receive an email and log it to the chatter in contacts? Rezolvat
email chatter v18
Imagine profil
Imagine profil
1
sept. 25
1587
Modify Pivot View
Pivot v18 CommunityEdition
Imagine profil
Imagine profil
1
iun. 25
1705
Unable to send email notifications through write
notifications v18 CommunityEdition
Imagine profil
Imagine profil
1
iun. 25
1747
How do i attach images from my custom email template?
email sale.order mailtemplate
Imagine profil
Imagine profil
1
sept. 23
4031
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now