I have a plugin that uses an email template.
I want to insert the contact name at the start of the email, ie. "Dear xxx", but I don't know how to access the email body.
Here's my code, which all works fine:
public void SendEmail(IOrganizationService service, Guid contactId, string emailSubject, string emailDescription, Guid fromActivityPartyGuid, Guid emailTemplateId, Guid regardingId, string regardingType)
{
CreateRequest reqCreateEmail = new CreateRequest();
Entity emailToSend = new Entity("email");
emailToSend["subject"] = emailSubject;
emailToSend["description"] = emailDescription;
Entity toActivityParty = new Entity("activityparty");
toActivityParty["partyid"] = new EntityReference("contact", contactId);
Entity[] emailToParty = { toActivityParty };
emailToSend["to"] = emailToParty;
Entity fromActivityParty = new Entity("activityparty");
fromActivityParty["partyid"] = new EntityReference("queue", fromActivityPartyGuid);
Entity[] emailFromParty = { fromActivityParty };
emailToSend["from"] = emailFromParty;
// Create the request to send email
SendEmailFromTemplateRequest emailUsingTemplateReq = new SendEmailFromTemplateRequest
{
Target = emailToSend,
// Use a built-in Email Template
TemplateId = emailTemplateId,
RegardingId = regardingId,
RegardingType = regardingType
};
try
{
SendEmailFromTemplateResponse emailUsingTemplateResp = (SendEmailFromTemplateResponse)service.Execute(emailUsingTemplateReq);
Guid _emailId = emailUsingTemplateResp.Id;
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException("An error occurred in the CommonFunctions.Email.SendEmail plug-in." + ex.Message, ex);
}
}
Basically, I want to do something like String.replace, find <name> and replace it with the recipient's name. Can this be done with an email template?
Thanks.