Call to method:
sendEmail(new Guid("7891B00E-ED80-E211-B2EA-02BFAC1A6434"), owner.Key, "systemuser", "Test Email", "Test Description", owner.Value);
Method:
private void sendEmail(Guid From, Guid To, string ToEntitySchemaName, string Subject, string Description, List<string> urls)
{
var description = new StringBuilder();
description.AppendLine("Hello,");
description.AppendLine("Text");
description.AppendLine("<ul>");
foreach (var address in urls) {
description.AppendFormat("<li>{0}</li>", string.Format(HyperLinkFormat, address, "Link to things"));
}
description.AppendLine("</ul>");
try
{
// Create 'From' activity party for the email
ActivityParty fromParty = new ActivityParty
{
PartyId = new EntityReference(SystemUser.EntityLogicalName, From)
};
// Create 'To' activity party for the email
ActivityParty toParty = new ActivityParty
{
PartyId = new EntityReference(ToEntitySchemaName, To)
};
// Create an e-mail message
Email email = new Email
{
To = new ActivityParty[] { toParty },
From = new ActivityParty[] { fromParty },
Subject = Subject,
Description = description.ToString(),
DirectionCode = true
};
Guid _emailId = _service.Create(email);
SendEmailRequest sendEmailreq = new SendEmailRequest
{
EmailId = _emailId,
TrackingToken = "",
IssueSend = true
};
SendEmailResponse sendEmailresp = (SendEmailResponse)_service.Execute(sendEmailreq);
if (sendEmailresp != null)
{
//Console.WriteLine("Email record created successfully");
//Console.ReadKey();
}
}
catch (Exception ex)
{
//Console.Write("Errorex.Message);
//Console.ReadKey();
throw new InvalidPluginExecutionException(ex.Message);
}
}