InstantiateTemplateRequest instTemplateReq = new InstantiateTemplateRequest
{
TemplateId = templateId, //template guid
ObjectId = incidentId, // template type id
ObjectType = "incident"
};
InstantiateTemplateResponse instTemplateResp = (InstantiateTemplateResponse)service.Execute(instTemplateReq);
Entity instTemplate = (Entity)instTemplateResp.EntityCollection.Entities[0];
Guid emailGuid = service.Create(instTemplate);
//Add attachement
Entity emailAttachment = new Entity("activitymimeattachment");
//attachement in byte[]
emailAttachment["body"] = Convert.ToBase64String(attachement);
emailAttachment["objectid"] = new EntityReference("email", emailGuid);
emailAttachment["objecttypecode"] = "email";
emailAttachment["filename"] = item.Name;
service.Create(emailAttachment); //Creates attachement to email
SendEmailRequest sendEmailReq = new SendEmailRequest()
{
EmailId = emailGuid,
IssueSend = true
};
SendEmailResponse sendEmailResp = (SendEmailResponse)service.Execute(sendEmailReq);
Wednesday, February 14, 2018
SDK - Send Email Using Template with attachement
Labels:
email templates,
sdk,
XRM
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment