List<ActivityParty> ccUsers = CCUsers(string ccEmails);
List<ActivityParty> toUsers = DNSTeamUsers();
CreateEmail(toUsers, ccUsers, subject, body);
//Create Email address, email will be in Draft format.List<ActivityParty> toUsers = DNSTeamUsers();
CreateEmail(toUsers, ccUsers, subject, body);
private Guid CreateEmail(List<ActivityParty> toUsers, List<ActivityParty> ccUsers, string subject, string body)
{
Guid orgid, userid;
SystemUserEntity.WhoAmIResponse(out orgid, out userid);
ActivityParty fromUser = new ActivityParty
{
PartyId = new EntityReference(SystemUser.EntityLogicalName, userid)
};
Email email = new Email();
email.From = new ActivityParty[] { fromUser };
if (toUsers!=null)
email.To = toUsers.ToArray();
if (ccUsers!=null)
email.Bcc = ccUsers.ToArray();
email.Subject = subject;
email.Description = body;
//Assign regarding
email.RegardingObjectId = new EntityReference(contact.EntityLogicalName, contactid);
//connect OrganizationServiceProxy
Guid emailGUID = CRMServiceProxy.Create(email);
return emailGUID;
}
{
Guid orgid, userid;
SystemUserEntity.WhoAmIResponse(out orgid, out userid);
ActivityParty fromUser = new ActivityParty
{
PartyId = new EntityReference(SystemUser.EntityLogicalName, userid)
};
Email email = new Email();
email.From = new ActivityParty[] { fromUser };
if (toUsers!=null)
email.To = toUsers.ToArray();
if (ccUsers!=null)
email.Bcc = ccUsers.ToArray();
email.Subject = subject;
email.Description = body;
//Assign regarding
email.RegardingObjectId = new EntityReference(contact.EntityLogicalName, contactid);
//connect OrganizationServiceProxy
Guid emailGUID = CRMServiceProxy.Create(email);
return emailGUID;
}