zoukankan      html  css  js  c++  java
  • Odoo14学习笔记(9) 发送提醒邮件

    第一步: 配置SMTP地址:设置 - 技术 - 电子邮件-发件服务器

     点击“测试连接”,出现下面提示即表示配置成功

     第二步: 创建邮件内容模板,记得在__manifest__.py中添加引用。简单的模块内容如下:

    <?xml version='1.0' encoding='UTF-8' ?>
    <odoo>
        <data noupdate="0">
            <record id="send_msg_template" model="mail.template">
                <field name="name">邮件提醒</field>
                <field name="email_from">xxx@xxx.com</field>
                <field name="subject">标题</field>
                <field name="model_id" ref="xxx.model_model_id"/>
                <field name="email_to">xxx@xxx.com</field>
                <field name="body_html" type="html">
                    <html>
                        <head>
                            <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
                            <title>内容标题</title>
                            <style>
                                span.oe_mail_footer_access {
                                display:block;
                                text-align:center;
                                color:grey;
                                }
                            </style>
                        </head>
                        <body>
                            <div style="border-radius: 2px; max- 1200px; height: auto;margin-left: auto;margin-right: auto;background-color:#f9f9f9;">
                                <div style="height:auto;text-align: center;font-size : 30px;color: #8A89BA;">
                                    <strong>邮件内容</strong>
                                </div>
                            </div>
                        </body>
                    </html>
                </field>
            </record>
        </data>
    </odoo>

     第三步:触发,在重新create方法、onchange事件或其它方法中均可触发。下例是在新建员工重写create方法中触发。

    
    
    @api.model
    def create(self, values):
    new_employee = super(employee, self).create(values)

    try:
    mail_template = self.env.ref('xxx.send_msg_template')
    mail_template.subject = u'xxx提醒 - %s' % new_employee.employeeName
    mail_template.send_mail(self.id, force_send=True)
    finally:
    aa = ""

    return new_employee
    
    

     另外需要在 __manifest__.py 中引用mail类,如:

     # any module necessary for this one to work correctly
     'depends': ['base','base_setup','base_import','mail'],
  • 相关阅读:
    FFT 优化和任意模数 FFT
    构造 DFT :某少女附中的体育课 题解
    多项式操作
    String主要方法
    我的第一篇java笔记
    个人作业——软件评测
    软件工程实践2019第五次作业
    软件工程实践2019第四次作业
    软件工程实践2019第三次作业
    软件工程实践2019第二次作业
  • 原文地址:https://www.cnblogs.com/61007257Steven/p/15211392.html
Copyright © 2011-2022 走看看