I want to forward received emails including all attachments, description, subject to another email.
My understanding is that I may need to create a plugin or custom workflow. I could see a code on this page but experiencing problem editing it. Please help with the modification so that it will use the received description, subject and all attachments to send a new email:
public class EMailPlugin : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
Entity account = (Entity)context.InputParameters["Target"];
Entity email = new Entity("email");
Entity fromParty = new Entity("activityparty");
Entity toParty = new Entity("activityparty");
toParty["partyid"] = new EntityReference("systemuser", context.UserId);
fromParty["partyid"] = new EntityReference("systemuser", context.UserId);
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", account.Id);
Guid emailId = service.Create(email);
SendEmailRequest sendEmailreq = new SendEmailRequest
{
EmailId = emailId,
TrackingToken = "",
IssueSend = true
};
SendEmailResponse sendEmailresp = (SendEmailResponse)service.Execute(sendEmailreq);
}
}
}