Skip to Content
Menu
This question has been flagged

Hello everyone, 

I'm trying to send messages with attachments in mailbox using xmlrpc (ir.attachment and mail.channel).

With admin account as sender, I can see my attachments without any problem. But as receiver in the same chat conversation, the images are not shown (I see just camera icon) and pdf files have the following error: PDF.js Version 2.2.228 (build: d7afb74a)
Message: Missing PDF "http://10.20.168.7:8069/web/content/884".

Here is a part of my script:

with open(attachment_filepath ,'rb') as raw_data:
​attachment1 = base64.b64encode(raw_data.read())
attachment = attachment1.decode('ascii')
file_type = re.search('\.(.*)',entry_name)
filetype = file_type.group()
name = 'attachment' + filetype
 
if filetype == '.pdf':
​mimetype = 'application/pdf'
elif filetype == '.jpg' or filetype == '.jpeg' :
​mimetype = 'image/jpeg'
elif filetype == '.png':
​mimetype = 'image/png'
else:
​mimetype = 'text/plain' 
 
if has_attachment is True:
​attach_args = [{
​'name' : name,
​'datas' : attachment,
​'store_fname' :attachment,
​'mimetype' : mimetype,
​'type': 'binary', 
​}]
​attachment_exe = models.execute_kw(db, uid, API_KEY, 'ir.attachment', 'create', attach_args)
​attachment_ids = [attachment_exe]
else:
​attachment_ids = []

args = [{
​'author_id': 3,
​'email_from': 'administrator',
​'create_uid': [2, 'administrator'],
​'subject': subject,
​'body': body,
​'attachment_ids' : attachment_ids,
​'message_type' : 'email',
​'model' : 'mail.channel',
​'starred': True,
​'reply_to': 'administrator',
​'partner_ids': partner_ids,
​'reaction_ids' : [3],
​'is_internal' : True,
​'reply_to_force_new': True,
​'mail_server_id': 1,
​'parent_id' : False,
​'res_id' : res_id,
}]
message = models.execute_kw(db, uid, API_KEY, 'mail.message', 'create', args)

Is it something related to access right? Does anybody have an idea?


Thank you in advance

Maryam

Avatar
Discard
Best Answer

It seems like you're running into an issue with the permissions of the user account you're using to send the messages with attachments. The images and pdf files are not being displayed properly because the user account you're using does not have the necessary permissions to access the attachments.

You can check the permissions of the user account by going to Settings > Users > Users and editing the user account in question. On the Access Rights tab, you can check if the user has the correct permissions to access the attachments.

One thing you can try is to give the user account permissions to access the ir.attachment model and the mail.channel model by setting the appropriate access rights. Another thing you can try is to check the permissions for the group the user is in.

Make sure that the user has the correct permissions to access the attachments and also check that the user has the correct access rights to the ir.attachment and mail.channel models. This should resolve the issue with the images and pdf files not being displayed properly.

Avatar
Discard
Related Posts Replies Views Activity
1
Aug 23
10962
0
Jun 20
61
1
May 24
1385
1
Nov 22
1892
3
Jun 22
4900