Email Template in odoo
1. Make one email template file inside data folder inside addons of your application and mention on manifest file as well.
example: student_email.xml
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<record id="school_student_invitation_mail_template" model="mail.template">
<field name="name">Invitation Mail</field>
<field name="model_id" ref="school.model_school_student"/>
<field name="subject">Invitation Mail</field>
<field name="email_to">{{object.email}}</field>
<!-- for attachment -->
<field name="report_template" ref="module_name.action_id_of_report"/>
<field name="report_name">Student_{{object.name}}_report</field>
<field name="body_html" type="html">
<!-- custom variable -->
<t t-set='user' t-value='object'/>
<span t-out='user.name'/>
<span t-out='user.get_full_name()'/>
<!-- custom variable -->
<t t-set='count' t-value='0'/>
<t t-set='count' t-value='count+1'/>
<p>Hello, <span t-field="object.name"/>.</p>
<p>Welcome to <t t-out="env.company.name or ''">YourCompany</t>! We are thrilled to have you on our family.</p>
<p>Email: <span t-out="object.email"/></p>
<!-- condition rendering -->
<p t-if='object.phone'>Phone: <span t-out="object.phone"/></p>
<t t-if='object.department_id'>
<p>Department: <span t-field='object.department_id.name'/></p>
</t>
<t t-elif='object.semester_id'>
<p>Semester: <span t-field='object.semester_id.name'/></p>
</t>
<t t-else=''>
<p>Age: <span t-field='object.age'/></p>
</t>
<!-- looping -->
<t t-if='object.id in [1,2,3,4,5,6,7,8,9]'>
<p>User found</p>
</t>
<p>Language List</p>
<t t-set="languages" t-value="['english','nepali','hindi']"/>
<t t-foreach='languages' t-as='language'>
<ul>(<span t-out='language_index'/>) <span t-out='language'/></ul>
<ul> <span t-out='language_odd'/></ul>
<ul> <span t-out='language_even'/></ul>
<ul> <span t-out='language_first'/></ul>
<ul> <span t-out='language_last'/></ul>
<ul> <span t-out='language_rct'/></ul>
<ul> <span t-out='language_rct_value'/></ul>
<ul> <span t-out='language_parity'/></ul>
</t>
<!-- image -->
<image src='/school/static/description/icon.png' style='width:50px;height:50px,object-fit:cover;' alt='image-not-found'/>
<br/>
<image t-attf-src='data:image/png;base64,{{object.image}}' style='width:50px;height:50px,object-fit:cover;' alt='image-not-found'/>
<p>Email: <span t-out="object.email"/></p>
<br/>
<p>If you have any questions or need assistance, feel free to reach out to our support team.</p>
<p>Best regards,</p>
<p><t t-out="env.company.name or ''">YourCompany</t></p>
</field>
</record>
</data>
</odoo>
2.How to sent email from code
def sending_mail(self):
self.env.ref('module_name.email_template_record_id').send_mail(self.id,force_send=True)
how to send email by button click
def send_mail(self):
template_id=self.env['model_name.template_id'].id
templte=self.env['mail.template'].browse(template_id)
template.send_mail(self.id,force_send=True)
# here self.id is the record id of btn click
Amanda Martines 5 days ago
Exercitation photo booth stumptown tote bag Banksy, elit small batch freegan sed. Craft beer elit seitan exercitation, photo booth et 8-bit kale chips proident chillwave deep v laborum. Aliquip veniam delectus, Marfa eiusmod Pinterest in do umami readymade swag. Selfies iPhone Kickstarter, drinking vinegar jean.
ReplyBaltej Singh 5 days ago
Drinking vinegar stumptown yr pop-up artisan sunt. Deep v cliche lomo biodiesel Neutra selfies. Shorts fixie consequat flexitarian four loko tempor duis single-origin coffee. Banksy, elit small.
ReplyMarie Johnson 5 days ago
Kickstarter seitan retro. Drinking vinegar stumptown yr pop-up artisan sunt. Deep v cliche lomo biodiesel Neutra selfies. Shorts fixie consequat flexitarian four loko tempor duis single-origin coffee. Banksy, elit small.
Reply