I have a requirement to send email to recipients not in crm.
That is not a look up to the party activity entity ..how can this be achieved the current code only allows a look up
Guid fromID = context.UserId; Entity sendEmail = new Entity("email"); Entity fromReciepent = new Entity("activityparty"); fromReciepent["partyid"] = new EntityReference("systemuser", fromID); //gets the look up sendEmail["subject"] = emailSubject; sendEmail["from"] = new Entity[] { fromReciepent }; // this works sendEmail["description"] = fullhtml; sendEmail["bcc"] = "test@yahoo.com "; // This does not work, sendEmail["to"] = new Entity[] { fromReciepent }; //this works
Guid emailID = service.Create(sendEmail); SendEmailRequest reqSendEmail = new SendEmailRequest(); reqSendEmail.EmailId = emailID; reqSendEmail.IssueSend = true; reqSendEmail.TrackingToken = ""; service.Execute(reqSendEmail);
The code works but am more concerned about this line that does not work because it is the most important
sendEmail["bcc"] = "test@yahoo.com ";
I have changed the settings on CRM to allow unresolved recipients
and have tested it from the front end, so why does it not work with the code.
*This post is locked for comments
Perfect thanks
Try to use following:
EntityCollection colAP = new EntityCollection();
foreach (var item in userResult.Entities)
{
Entity activityParty = new Entity("activityparty");
activityParty["addressused"] = item.Attributes["internalemailaddress"];
colAP.Entities.Add(activityParty);
}
email["bcc"] = colAP;
Thanks this worked perfectly, but created another error which is invalid email.
Actually the emails exists on the , so may be it is why I get an invalid email error.
so its a batch job to send email to a lot of users hence the bcc
so the code below shows it
string usersxml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> <entity name='systemuser'> <attribute name='fullname' /> <attribute name='systemuserid' /> <attribute name='internalemailaddress' /> <order attribute='fullname' descending='false' /> <filter type='and'> <condition attribute='isdisabled' operator='eq' value='0' /> <condition attribute='internalemailaddress' operator='not-null' /> </filter> </entity> </fetch>"; EntityCollection userResult = service.RetrieveMultiple(new FetchExpression(usersxml)); string emailList = ""; foreach (var item in userResult.Entities) { emailList += item.Attributes["internalemailaddress"]+";"; }
So the email list will be user1@email.com;user2@email.com;user3@email.com;
and so on..so when i put this on the bcc it throws an error...saying more than one match was found...
is there a better way I can populate the bcc with lots of users on the system like the fectxml..
else you already answered this question .
Regard
Hello,
Check following - paul-way.com/sending-unresolved-emails
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156