Send Email request In MS CRM


Entity email = new Entity(“email”);
Entity fromParty = new Entity(“activityparty”);
Entity toParty = new Entity(“activityparty”);
fromParty[“partyid”] = new EntityReference(“systemuser”, userId);
toParty[“partyid”] = new EntityReference(“account”, accountId);
email[“from”] = new Entity[] { fromParty };
email[“to”] = new Entity[] { toParty };
email[“subject”] = “email subject – ” + DateTime.Now.ToString();
email[“description”] = “email description”;
email[“regardingobjectid”] = new EntityReference(“account”,accountId);
Guid emailId = service.Create(email);
if (emailId != Guid.Empty)
{
SendEmailRequest sendEmailreq = new SendEmailRequest()
{
EmailId = emailId,
TrackingToken = “”,
IssueSend = true
};
SendEmailResponse sendEmailresp = (SendEmailResponse)service.Execute(sendEmailreq);
}