0

I am sending an email in a case using emailMessage in python. I can see it updated in the case but the email isnt actually sent. I have hardcoded the FromAddress and ToAddress.

My request is as follows:

import requests

import os

from simple_salesforce import Salesforce

sf_pass = os.environ['SALESFORCE_API_KEY'].split('!')[0] + '!'
sf_token = os.environ['SALESFORCE_API_KEY'].split('!')[1]
sf_user = os.environ['SALESFORCE_API_EMAIL']

sf = Salesforce(username=sf_user, password=sf_pass, security_token=sf_token)

session_id = sf.session_id

base_url = "https://mybaseurl.com"

case_id = "XXXXXXXXXXX"

email_subject = "This is working"

email = "[email protected]"

from_address = "[email protected]"

email_body = "Dear customer, \n\nWe have received your case and are working on it. We will update you soon with further information.\n\nBest Regards,\nThe Support Team"

email_payload = {
    "Subject": email_subject,
    "TextBody": email_body,
    "ParentId": case_id,
    "ToAddress": email,
    "FromAddress": from_address
}

url = f"{base_url}/services/data/v58.0/sobjects/EmailMessage"
headers = {
    "Authorization": f"Bearer {session_id}",
    "Content-Type": "application/json"
}

response = requests.post(url, headers=headers, json=email_payload)

if response.status_code == 201:
    print(f"Email sent successfully!: {response.status_code}, Response: {response.json()}")
else:
    print(f"Failed to send email. Status code: {response.status_code}, Response: {response.json()}")
5

1 Answer 1

0

All posting a email message to

/services/data/v58.0/sobjects/EmailMessage

will do is make a record on your org of that email message. This has nothing to do with actually sending the message you need to either:

  1. make a trigger (flow/apex) to take this newly inserted email message and send it
  2. call a standard invokable action remotely here
  3. make your own invokeable rest call in apex
2
  • Hi @KarlLivesey Can the email created via simpleEmail be linked to a case? Aug 3, 2023 at 14:17
  • @user2249295 Yes you can if in the input provided see link below for documentation you specify "logEmailOnSend" as true and specify the related record Id in "relatedRecordId" it will automatically log the email against this in salesforce on successful send and will appear in the timeline. developer.salesforce.com/docs/atlas.en-us.api_action.meta/… Aug 4, 2023 at 10:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .