Salesforce API: Creating EmailMessage and associating a Contact possible?
<p>I'm working on a project where (already sent) emails should be saved to Salesforce and matched with the corresponding Salesforce contact.</p>

<p>Creating new Emails is rather straightforward. For example using the simple_salesforce python library my code looks like this:</p>

<pre><code>from simple_salesforce import Salesforce

[…]

sf = Salesforce(instance_url=instance_url, session_id=session_id)
sf.EmailMessage.create(
    {'FromAddress': 'foo@example.com',
     'ToAddress': 'bar@example.com',
     'Subject': 'Email: Fancy Subject', 
     'TextBody': 'lorem ipsum dolor sit amet',  
     'Status': 2
    })
</code></pre>

<p>This successfully creates a new EmailMessage but the message is not matched to the contact (assuming bar@example.com is an exisiting contact in Salesfored). This can be seen in numerous places in the Salesforce UI. For example:</p>

<ul>
<li>It is not part of the contact's activity history</li>
<li>When looking at the Email Message details, the section “Sender and Recipients” is empty</li>
</ul>

<p>When creating new emails using the Salesforce UI, the association is done correctly. Comparing my <code>EmailMessage</code> objects from the ones generate by Salesforce there is one obvious difference: <code>ActivityId</code> is not set for my objects.</p>

<p>When I'm trying to set <code>ActivityId</code> I receive a Malformed Request Exception <code>INSUFFICIENT_ACCESS_OR_READONLY</code>.</p>

<p>Is it somehow possible to create those associations using the API?</p>