How can I make it so that an email is sent to all users (employees) whenever a new forum post is created?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- 客户关系管理
- e-Commerce
- 会计
- 库存
- PoS
- Project
- MRP
此问题已终结
To make Odoo 13 Forums send an email notification to all users (e.g., employees) whenever a new forum post is created, you need to configure automated actions or use Odoo’s built-in email notification system. Below are the steps to achieve this:
1. Enable Notifications for Forum Posts
By default, Odoo Forums allow followers of a forum or specific posts to receive notifications. To ensure all employees are notified:
-
Add All Employees as Followers:
-
Navigate to the forum you want to track:
- Go to Website > Forums and open the specific forum.
- Click on the Follow button and manually add all employees as followers.
Tip: Ensure all employees have access to their Odoo accounts and valid email addresses.
-
Navigate to the forum you want to track:
-
Default Followers on Forum Creation (Optional):
- Use Odoo Studio or development tools to make employees follow newly created posts automatically.
2. Use Automated Actions
To send an email notification to all employees when a new post is created, you can create a custom Automated Action.
Steps to Configure Automated Action:
-
Activate Developer Mode:
- Go to Settings > Activate Developer Mode.
-
Create the Automated Action:
- Navigate to Settings > Technical > Automation > Automated Actions.
- Click Create and configure as follows:
- Model: Forum Post (forum.post).
- Trigger: On Creation.
- Action To Do: Send Email.
-
Configure Email Template:
- In the same automated action, set up an email:
- Recipients:
- Select All Employees.
- Alternatively, you can create a mailing list of employees.
- Email Template:
- Create a new email template to format the message with details about the forum post.
- Example template:
<p>Hello,</p> <p>A new forum post has been created:</p> <ul> <li>Title: ${object.name}</li> <li>Author: ${object.create_uid.name}</li> <li>Link: <a href="${object.website_url}">${object.website_url}</a></li> </ul> <p>Best regards,<br/>Odoo Forums</p>
- Recipients:
- In the same automated action, set up an email:
-
Test the Automated Action:
- Create a new forum post and check if the email notification is sent successfully.
3. Enable Mailing via Odoo Studio
If you’re using Odoo Studio, you can directly add the email-sending logic without needing to write Python code.
Steps:
- Open the Forum module in Studio.
-
Add a server action to the forum.post model:
- Trigger: On Creation.
- Action: Send Email.
- Use the template you created earlier to notify all employees.
4. Custom Python Code (Optional)
If you want more control, you can create a custom module to handle email notifications for forum posts.
Example Code:
from odoo import models, api class ForumPost(models.Model): _inherit = 'forum.post' @api.model create(vals): # Call the original create method post = super(ForumPost, self).create(vals) # Notify employees employees = self.env['res.users'].search([('groups_id', 'in', self.env.ref('base.group_user').id)]) for employee in employees: template = self.env.ref('module_name.new_forum_post_email_template') self.env['mail.template'].browse(template.id).send_mail(post.id, email_values={'recipient_ids': [(4, employee.partner_id.id)]}) return post
- Replace module_name.new_forum_post_email_template with the XML ID of your email template.
- Place the code in a custom module, and ensure the module is installed.
5. Additional Tips
- Unsubscribe Option:
- If you notify all employees, provide a way for users to unsubscribe from notifications. Add a link in the email to manage subscriptions.
- Performance Optimization:
- For large organizations, sending emails to many users might slow down the system. Consider batching or using a queue.
- Email Delivery Logs:
- Navigate to Settings > Technical > Emails > Emails to check if emails are sent successfully.
By using these methods, you can ensure that all employees receive notifications whenever a new forum post is created. Let me know if you need further assistance or detailed guidance on implementing these steps!
相关帖文 | 回复 | 查看 | 活动 | |
---|---|---|---|---|
|
1
8月 25
|
1538 | ||
|
1
5月 25
|
1249 | ||
|
2
5月 25
|
1386 | ||
|
0
4月 25
|
1109 | ||
|
1
3月 25
|
1604 |