Search code examples
pythonemailexchange-serverexchangelib

What is the changekey of Messages in exchangelib?


I am trying to give the users additional information about emails they received in form of an email in the same conversation.

What I do

from exchangelib import Message

# Works:
account = Account(primary_smtp_address=smtp_address, config=config,
                  autodiscover=False, access_type=DELEGATE)
mail = A message received under account

# Works, but probably needs adjustment:
m = Message(account=account,
            subject=mail.subject,
            conversation_id=mail.conversation_id,
            body='Test',
            to_recipients=[account.primary_smtp_address])

# Throws error below
m.send()

I get

Traceback (most recent call last):
  File "myscript.py", line 114, in myfunction
    m.send()
  File "/usr/local/lib/python2.7/dist-packages/exchangelib/items.py", line 507, in send
    res = self._create(message_disposition=SEND_ONLY, send_meeting_invitations=send_meeting_invitations)
  File "/usr/local/lib/python2.7/dist-packages/exchangelib/items.py", line 176, in _create
    send_meeting_invitations=send_meeting_invitations)
  File "/usr/local/lib/python2.7/dist-packages/exchangelib/account.py", line 260, in bulk_create
    send_meeting_invitations=send_meeting_invitations,
  File "/usr/local/lib/python2.7/dist-packages/exchangelib/account.py", line 254, in <genexpr>
    i if isinstance(i, Exception)
  File "/usr/local/lib/python2.7/dist-packages/exchangelib/services.py", line 451, in _pool_requests
    elems = r.get()
  File "/usr/lib/python2.7/multiprocessing/pool.py", line 567, in get
    raise self._value
ValueError: 'changekey' is a required field with no default

What is the problem and how do I fix it?


Solution

  • The problem is that I set conversation_id. It is actually not necessary to set the conversation ID if I only want the message to be shown in the same conversation. Only setting the subject line exactly the same seems to be enough.