Emailing through Salesforce in the third-party applications can be achieved through Salesforce REST endpoint services/data/v61.0/actions/standard/emailSimple
Below is the sample code in .Net for sending simple plain text email for emailing through Salesforce
public void SendEmailUsingSalesforce()
{
Dictionary
var emailData = new
{
inputs = new[]
{
new
{
emailAddressesArray =
emailSubject =
emailBody =
senderType="OrgWideEmailAddress",
senderAddress =
saveAsActivity = true // Save as activity record in Salesforce
}
}
};
//To send a comma separated list of the recipient’s email addresses, emailAddresses field //can be used instead of emailAddressesArray
string jsonBody = JsonConvert.SerializeObject(emailData);
string requestUrl = "{instance-url}/services/data/v61.0//actions/standard/emailSimple";
string result = Task.Run(async () => await PostSalesforceAsync(requestUrl, _salesforecToken.access_token, jsonBody)).Result;
}
public static async Task
{
string responseString = string.Empty;
try
{
using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post,
requestUrl))
{
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer",
accessToken);
request.Content = new StringContent(jsonBody, Encoding.UTF8,
"application/json");
HttpResponseMessage response = await _httpClient.SendAsync(request);
if (response.IsSuccessStatusCode)
{
responseString = await response.Content.ReadAsStringAsync();
if (string.IsNullOrEmpty(responseString))
{
responseString = "success";
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
Console.WriteLine($"Context: {requestUrl}");
}
return responseString;
}
To send the rich text, set the property sendRichBody to true in Email Json