Good Day,
I have CRM email router set up to exchange 2010.
I once the email enters CRM i am supposed to create another email with a different body and link to the previous incoming email and forward this to another email address.
My challenge is in attachments,an email enters CRM with attachments but once I forward as outgoing email it then loses all the attachments.
I need to be able to forward this emails together with all the attachments how can I achieve this?
and again any signature contain a drawing is displayed as html on the new email how can I display this as it is like in the original incoming email?
I have followed a few guidelines online but they did not do much because I copied the code as it is but really no attachments are sent see below address here
the links suggest I use a workflow activity but this workflow activity is not working as expected maybe I have my code wrong.
See code below.
Thanks
using System;
namespace MoveAttachmentsToCase
{
public class MoveAttachmentsToCase :CodeActivity
{
//define output variable
[Input("SourceEmail")]
[ReferenceTarget("email")]
public InArgument<EntityReference> SourceEmail { get; set; }
protected override void Execute(CodeActivityContext executionContext)
{ //Create the service object
IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
// Get the e-mail reference object
// Get the target entity from the context
// Get the target entity from the context
Entity AccountID= (Entity)service.Retrieve("email", context.PrimaryEntityId, new ColumnSet(new string[] { "activityid" }));
AddAttachmentToEmailRecord(service, AccountID.Id, SourceEmail.Get<EntityReference>(executionContext));
}
private void AddAttachmentToEmailRecord(IOrganizationService service, Guid SourceAccountID, EntityReference SourceEmailID)
{
//create email object
Entity _ResultEntity = service.Retrieve("email", SourceEmailID.Id, new ColumnSet(true));
QueryExpression _QueryNotes = new QueryExpression("annotation");
_QueryNotes.ColumnSet = new ColumnSet(new string[] { "subject", "mimetype", "filename", "documentbody" });
_QueryNotes.Criteria = new FilterExpression();
_QueryNotes.Criteria.FilterOperator = LogicalOperator.And;
_QueryNotes.Criteria.AddCondition(new ConditionExpression("objectid", ConditionOperator.Equal, SourceAccountID));
EntityCollection _MimeCollection = service.RetrieveMultiple(_QueryNotes);
if (_MimeCollection.Entities.Count > 0)
{ //we need to fetch first attachment
Entity _NotesAttachment = _MimeCollection.Entities.First();
//Create email attachment
Entity _EmailAttachment = new Entity("activitymimeattachment");
if (_NotesAttachment.Contains("subject"))
_EmailAttachment["subject"] = _NotesAttachment.GetAttributeValue<string>("subject");
_EmailAttachment["objectid"] = new EntityReference("email", _ResultEntity.Id);
_EmailAttachment["objecttypecode"] = "email";
if (_NotesAttachment.Contains("filename"))
_EmailAttachment["filename"] = _NotesAttachment.GetAttributeValue<string>("filename");
if (_NotesAttachment.Contains("documentbody"))
_EmailAttachment["body"] = _NotesAttachment.GetAttributeValue<string>("documentbody");
if (_NotesAttachment.Contains("mimetype"))
_EmailAttachment["mimetype"] = _NotesAttachment.GetAttributeValue<string>("mimetype");
service.Create(_EmailAttachment);
}
}
}
}
*This post is locked for comments