Friday, August 26, 2011

Activity Party in Emails & Unresolved Email Addresses

Adjusting emails through custom code is a bit of a pain, but I managed to figure out how to modify the recipients of an email as well as force unresolved email addresses in there.

First, for unresolved emails, enable them in the CRM settings. Settings -> Administration -> System Settings -> Email Tab -> Allow messages with unresolved e-mail recipients to set -> Set to yes.

Now, onto the some code snippets. I know I learn best by looking at working code!

EntityCollection ec = new EntityCollection();
EntityCollection ccEC = new EntityCollection();

// Send to a CONTACT
Entity party = new Entity("activityparty");
party["partyid"] = new EntityReference("contact", contactId);                        party["participationtypemask"] = new OptionSetValue(2); // 2 for TO
ec.Entities.Add(party);

// Send to an EMAIL ADDRESS BY STRING
Entity ccParty = new Entity("activityparty");
ccParty["addressused"] = ccEmail.Trim(); // Raw email address string
ccParty["participationtypemask"] = new OptionSetValue(3); // 3 for CC
ccEC.Entities.Add(ccParty);

email["to"] = ec;
email["cc"] = ccEC;
crmService.Update(email); // I already had my email entity object prior to this

// Send the email!
SendEmailRequest ser = new SendEmailRequest();
ser.EmailId = email.Id;
ser.TrackingToken = "";
ser.IssueSend = true;
crmService.Execute(ser);

Hope this saves someone out there some pain! I know I beat my head against this for awhile before getting it all rolling.

No comments:

Post a Comment