Skip to Content
Menu
This question has been flagged
2 Replies
2494 Views

Hi there


Is there a way via XML RPC webservice, to send notification e-mails to the followers via XML RPC? 

(in other words when the record in mail.message with data is created, send mail with contents to the followers)


Avatar
Discard
Author Best Answer

Hi there. Many thanks for this quick and complete answer.

I'm trying to test it, but when i try this:

return self.models.execute_kw(self.dbName, self.uid, self.dbPassword, 'mail.thread', 'message_post', [[recordId], message, {}])

I get the message:

raise ValueError("Expected singleton: %s" % self)\nValueError: Expected singleton: mail.thread([291159], \'test bericht\', {})\n'>

Can you tell me what i'm doing wrong?



Avatar
Discard
Best Answer

Hi,

Yes, you can send notification emails to the followers of a record in Odoo via XML-RPC web services. Odoo provides various methods in its XML-RPC API to achieve this.

To send notification emails to the followers of a record, you can use the message_post method from the mail.thread model. Here's a high-level overview of how to do it:

  1. Authenticate your XML-RPC client with your Odoo instance.
  2. Locate the record for which you want to send notifications. You'll need to have the ID of the record you want to notify the followers about.
  3. Call the message_post method with the appropriate parameters to send the notification email. Here's a basic example in Python:

import xmlrpc.client

url = 'http://your-odoo-instance.com'
db = 'your-database-name'
username = 'your-username'
password = 'your-password'

common = xmlrpc.client.ServerProxy(f'{url}/xmlrpc/2/common')
uid = common.authenticate(db, username, password, {})

models = xmlrpc.client.ServerProxy(f'{url}/xmlrpc/2/object')

record_id = 123  # Replace with the ID of the record you want to notify followers about
message = "This is your notification message."

# Call message_post to send the notification email
models.execute_kw(db, uid, password, 'mail.thread', 'message_post', [[record_id], message, {}])

In this example, you need to replace the placeholders with your actual Odoo instance details and the ID of the record you want to notify. You can also customize the message variable to include the content of the email.

Make sure that the user specified in the authentication process has the necessary permissions to send messages and notify followers. Additionally, you may need to handle error handling and exceptions in your code to ensure robust functionality.

By using the message_post method, you can send notification emails to the followers of a record via Odoo's XML-RPC web service.

Hope it helps

Avatar
Discard