hi ,
can you guys help me to find out the solution for sending email for users who are all not from MS CRM.
I have tried the below code but it is not working.or else vai workflow also but without creating account or contacts etc.
string[] emailname = { "srv@gmail.com;", "abc@gmail.com;" };
EntityCollection colAP = new EntityCollection();
Entity activityParty = new Entity("activityparty");
activityParty["addressused"] = emailname;
colAP.Entities.Add(activityParty);
Entity template = GetGlobalTemplate("Auto mail configuration for scheduling Risk Review", service);
Entity email = new Entity("email");
Entity from = new Entity("activityparty");
from["partyid"] = new EntityReference("systemuser", ContextObject.context.UserId);
tracingService.Trace("from:" + ContextObject.context.UserId.ToString());
Entity[] SendFrom = { from };
email["from"] = SendFrom;
email["to"] = colAP;
Guid EmailId = service.Create(email);
SendEmailFromTemplateRequest emailtempreq = new SendEmailFromTemplateRequest
{
Target = email,
TemplateId = template.Id,
RegardingId = targetEntity.Id,
RegardingType = "opportunity"
};
SendEmailFromTemplateResponse emailtempresp = (SendEmailFromTemplateResponse)service.Execute(emailtempreq);
awaiting for you reply,
Muthukumaran M.
*This post is locked for comments
hi Kokulan Eswaranathan (கோகுலன் ஈஸ்வரநாதன்),
we need to add some more think to your code to work i have attached my working code.
Thank you so much kokul.
Entity template = GetGlobalTemplate("Auto mail configuration for scheduling Risk Review", service);
Entity email = new Entity("email");
Entity from = new Entity("activityparty");
from["partyid"] = new EntityReference("systemuser", ContextObject.context.UserId);
tracingService.Trace("from:" + ContextObject.context.UserId.ToString());
Entity[] SendFrom = { from };
email["from"] = SendFrom;
EntityCollection colAP = new EntityCollection();
string[] emailname = {"srv@gmail.com", "abc@gmail.com" };
foreach (var emailAddress in emailname)
{
if (!string.IsNullOrWhiteSpace(emailAddress))
{
Entity toParty = new Entity("activityparty");
toParty.Attributes.Add("addressused", emailAddress);
colAP.Entities.Add(toParty); ;
}
}
email["to"] = colAP;
Guid EmailId = service.Create(email);
// Guid EmailId = service.Create(email);
SendEmailFromTemplateRequest emailtempreq = new SendEmailFromTemplateRequest
{
Target = email,
TemplateId = template.Id,
RegardingId = targetEntity.Id,
RegardingType = "opportunity"
};
SendEmailFromTemplateResponse emailtempresp = (SendEmailFromTemplateResponse)service.Execute(emailtempreq);
Regards,
Muthukumaran M,
L&T Infotech,
Karaikal,
Chennai.
India
Hi
Could you try the following code and see if this works for you?
string[] emailname = { "srv@gmail.com;", "abc@gmail.com;" };
List<Entity> colAP = new List<Entity>();
foreach (var emailAddress in emailname)
{
if (!string.IsNullOrWhiteSpace(emailAddress))
{
Entity toParty = new Entity("activityparty");
toParty["addressused"] = emailAddress;
colAP.Add(toParty);
}
}
Entity template = GetGlobalTemplate("Auto mail configuration for scheduling Risk Review", service);
Entity from = new Entity("activityparty");
from["partyid"] = new EntityReference("systemuser", ContextObject.context.UserId);
tracingService.Trace("from:" + ContextObject.context.UserId.ToString());
Entity[] SendFrom = { from };
Entity email = new Entity("email");
email["from"] = SendFrom;
email["to"] = colAP.ToArray();
SendEmailFromTemplateRequest emailtempreq = new SendEmailFromTemplateRequest
{
Target = email,
TemplateId = template.Id,
RegardingId = targetEntity.Id,
RegardingType = "opportunity"
};
Allowing CRM to send emails to unresolved email addresses, please see below
And if your users emails are not approved and if you want emails to be sent from those users, you will have to untick the following settings as well.
Mohamed Amine Mahmoudi
83
Super User 2025 Season 1
Community Member
52
Victor Onyebuchi
6