How to send email in encompass using codes

Here’s an example code in Python that demonstrates how to send an email using the Encompass API:

This is in ‘python’

import requests
import json

url = ‘https://api.elliemae.com/encompass/v1/borrowers/{}/email’

access_token = ‘YOUR_ACCESS_TOKEN’
borrower_id = ‘BORROWER_ID’

headers = {
‘Authorization’: f’Bearer {access_token}’,
‘Content-Type’: ‘application/json’
}

data = {
‘subject’: ‘Hello from Encompass’,
‘body’: ‘This is a test email sent from Encompass API’,
‘recipients’: [
{
’emailAddress’: ‘john.doe@example.com’,
‘recipientType’: ‘TO’
}
],
‘attachments’: [] }

response = requests.post(url.format(borrower_id), headers=headers, data=json.dumps(data))

if response.status_code == 200:
print(‘Email sent successfully.’)
else:
print(‘Failed to send email:’, response.text)

In this example, you will need to replace YOUR_ACCESS_TOKEN with a valid access token that you obtain from the Encompass API developer portal, and BORROWER_ID with the ID of the borrower you want to send the email to. You will also need to modify the email subject, body, and recipient email address according to your requirements.

Note that this is just a simple example, and there are many more parameters and options you can use to customize your email, such as adding attachments or specifying CC and BCC recipients. You can find more information about the Encompass API in the official documentation: https://developer.elliemae.com/docs/encompass/REST_API_Reference.

Here’s an example code in C# that demonstrates how to send an email using the Encompass API and an Input Form Builder (IFB) form as the user interface:

using EllieMae.Encompass.Api;
using EllieMae.Encompass.BusinessObjects.Loans;
using EllieMae.Encompass.BusinessObjects.Users;
using EllieMae.Encompass.Client;
using EllieMae.Encompass.Reporting;
using EllieMae.Encompass.Reporting.EncompassReportService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace EncompassEmailSender
{
public partial class MainForm : Form
{
private EncompassApplication _encompass;

public MainForm()
{
InitializeComponent();
_encompass = new EncompassApplication();
}

private async void btnSendEmail_Click(object sender, EventArgs e)
{
try
{
Loan loan = _encompass.CurrentLoan;
User currentUser = _encompass.Session.Users.CurrentUser;
string accessToken = _encompass.Session.AccessToken;

HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(“Bearer”, accessToken);

string borrowerId = loan.Borrowers[0].Id;
string emailEndpoint = $”https://api.elliemae.com/encompass/v1/borrowers/{borrowerId}/email”;

var emailData = new
{
subject = txtSubject.Text,
body = txtBody.Text,
recipients = new[] {
new
{
emailAddress = txtTo.Text,
recipientType = “TO”
}
},
attachments = new[] {
new
{
documentId = txtAttachmentDocId.Text,
attachmentType = “PDF”
}
}
};

var content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(emailData), Encoding.UTF8, “application/json”);
var response = await client.PostAsync(emailEndpoint, content);

if (response.IsSuccessStatusCode)
{
MessageBox.Show(“Email sent successfully.”);
}
else
{
string errorText = await response.Content.ReadAsStringAsync();
MessageBox.Show($”Failed to send email: {errorText}”);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}

In this example, you need to create a Windows Forms application in Visual Studio, and add an Input Form Builder form with the following fields:

  • txtTo (TextBox): the recipient email address
  • txtSubject (TextBox): the email subject
  • txtBody (TextBox): the email body
  • txtAttachmentDocId (TextBox): the Encompass document ID of the attachment (optional)

Then, you can handle the button click event to send the email using the Encompass API. The code first retrieves the current loan and user objects from Encompass, as well as the access token. It then creates an HTTP client and sends a POST request to the email endpoint with the email data specified by the user. Finally, it displays a message box to indicate whether the email was sent successfully or not.

Note that this example assumes that the user has already authenticated with Encompass and has the necessary permissions to send emails. It also assumes that you have already obtained an access token from the Encompass API developer portal and set up the Encompass SDK in your Visual Studio project.

Here’s an example code in C# that demonstrates how to send an email using an Encompass email template stored in a custom JSON data object and an Input Form Builder (IFB) form as the user interface:

using EllieMae.Encompass.Api;
using EllieMae.Encompass.BusinessObjects;
using EllieMae.Encompass.BusinessObjects.Loans;
using EllieMae.Encompass.Client;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace EncompassEmailSender
{
public partial class MainForm : Form
{
private EncompassApplication _encompass;

public MainForm()
{
InitializeComponent();
_encompass = new EncompassApplication();
}

private async void btnSendEmail_Click(object sender, EventArgs e)
{
try
{
Loan loan = _encompass.CurrentLoan;
User currentUser = _encompass.Session.Users.CurrentUser;
string accessToken = _encompass.Session.AccessToken;

string templateName = txtTemplateName.Text;
string borrowerId = loan.Borrowers[0].Id;

string emailEndpoint = $”https://api.elliemae.com/encompass/v1/borrowers/{borrowerId}/email?templateName={templateName}”;

var emailData = new
{
customDataObjects = new[] {
new
{
name = “EmailTemplate”,
values = new Dictionary<string, object>
{
{ “EmailSubject”, txtSubject.Text },
{ “EmailBody”, txtBody.Text }
}
}
},
recipients = new[] {
new
{
emailAddress = txtTo.Text,
recipientType = “TO”
}
}
};

var content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(emailData), Encoding.UTF8, “application/json”);

HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(“Bearer”, accessToken);

var response = await client.PostAsync(emailEndpoint, content);

if (response.IsSuccessStatusCode)
{
MessageBox.Show(“Email sent successfully.”);
}
else
{
string errorText = await response.Content.ReadAsStringAsync();
MessageBox.Show($”Failed to send email: {errorText}”);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}

In this example, you need to create a Windows Forms application in Visual Studio, and add an Input Form Builder form with the following fields:

  • txtTo (TextBox): the recipient email address
  • txtTemplateName (TextBox): the name of the Encompass email template stored in a custom JSON data object
  • txtSubject (TextBox): the email subject (will be replaced by the template subject)
  • txtBody (TextBox): the email body (will be replaced by the template body)

Then, you can handle the button click event to send the email using the Encompass API. The code first retrieves the current loan and user objects from Encompass, as well as the access token. It then constructs the email endpoint URL with the borrower ID, template name, and query parameter to indicate that an email template is being used. The email data includes a custom data object with the name “EmailTemplate” and two values for the email subject and body, respectively. It also includes the recipient email address. Finally, it sends a POST request to the email endpoint with the email data, and displays a message box to indicate whether the email was sent successfully or not.

Note that this example assumes that the custom JSON data object containing the email template exists in the loan

You may also like...

Popular Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.