Proteus and send mail

I am trying to send mail from proteus. I read the topic about the models (notes and attachement) but did not succeed, i must miss something (probably simple)

what i tried:

Party=Model.get('party.party')
the_party=Party.find([('code','=','my_code')])
print (the_party)
 >>>>party.party,25561
Mail=Model.get('ir.email')
to_mail=Mail()
to_mail.resource=the_party
to_mail.subject="subject by proteus"
to_mail.body="the content"
to_mail.recipients='contact <contact@fai.tld>'

to_mail.save() or  to_mail.click('send')

gives that
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/proteus/__init__.py", line 102, in newfunc
    return self.func(owner, [instance], *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/proteus/__init__.py", line 853, in save
    ids = proxy.create(values, context)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/proteus/config.py", line 193, in __call__
    raise TypeError('%s is not callable' % self._name)
TypeError: create is not callable

what did i miss ?

You must use the Email.send method. You can not create directly records in the ir.email table.

i tried some

Mail=Model.get('ir.email')
Mail.send(to='contact <herve@fai.tld>',subject='Le sujet',body='Le body')
 == AND
Mail.send(to_mail)
  == and 
Mail.send('contact <herve@fai.tld>','Le sujet','Le body')


and i have

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/proteus/config.py", line 198, in __call__
    rpc.convert(self._object, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/trytond/rpc.py", line 54, in convert
    raise ValueError("Missing context argument")
ValueError: Missing context argument

I did not find in the forum nor in ir/email.py a clue of the conetext missing. i evenTraceback (most recent call last):
File “”, line 1, in
File “/usr/lib/python3/dist-packages/proteus/config.py”, line 198, in call
rpc.convert(self._object, *args, **kwargs)
File “/usr/lib/python3/dist-packages/trytond/rpc.py”, line 54, in convert
raise ValueError(“Missing context argument”)
ValueError: Missing context argument try

to add resource like Mail.resource=the_party or like

Mail.send(to=‘contact <herve@fai.tld’,subject=‘Le sujet’,body=‘Le body’,resource=the_party)

but i have the same result, what i am missoing, where to find some code that would help me to understand ?

For RPC methods you always have to pass the context as the last argument, so something like this should work:

Mail = Model.get('ir.email')

to = "user@example.com"
cc = ""
bcc = ""
subject = "Hello from Proteus"
body = "This is a test email."
files = None
record = ['party.party', 1]
reports = None
attachments = None
context = {}

Mail.send(to, cc, bcc, subject, body, files, record, reports, attachments, context)

Keep in mind, the record always has to be set even if you do not send any files, reports or attachments.

Kind regards

i finally tried and succeed with files=”” instead of files = None

that was spitting

File “”, line 1, in
File “/usr/lib/python3/dist-packages/proteus/config.py”, line 202, in call
result = rpc.result(meth(*args, **kwargs))
^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3/dist-packages/trytond/ir/email_.py”, line 196, in send
for name, data in files:
TypeError: ‘NoneType’ object is not iterable

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.