Hi Pedro Pisco,
Thank you for the reply. I am able to get queued. But when I pass this queueid I got "
System.NullReferenceException: Object reference not set to an instance of an object." this exception.
Below is my code I am trying to send email
string queueName = "Business Sales Operations";
string fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='queue'>
<attribute name='name' />
<attribute name='emailaddress' />
<attribute name='queueid' />
<order attribute='name' descending='false' />
<filter type='and'>
<condition attribute='name' operator='eq' value='{0}' />
</filter>
</entity>
</fetch>";
EntityCollection result = service.RetrieveMultiple(new FetchExpression(String.Format(fetchXml, queueName)));
var myQueue = (Queue)result.Entities[0];
tracingService.Trace("My queue ID " + myQueue.Id);
// Create Email
Email email = new Email();
// Set the from user of the email to Logged in user
ActivityParty fromParty = new ActivityParty();
fromParty.PartyId = new EntityReference(SystemUser.EntityLogicalName, loggedinUser); //loggedinUser myQueue.Id
tracingService.Trace("fromParty.PartyId " + fromParty.PartyId.ToString());
string subject = string.Empty;
string description = string.Empty;
GetEmailData(caseStatus, out subject, out description, caseEntity, tracingService);
email.Subject = subject;
email.Description = description;
List<ActivityParty> lstTo = new List<ActivityParty>();
//List<ActivityParty> lstFrom = new List<ActivityParty>();
//var fromActivityParty = new ActivityParty();
//fromActivityParty.AddressUsed = "emailid@microsoft.com";
//lstFrom.Add(fromActivityParty);
//tracingService.Trace("Added " + "emailid@microsoft.com");
if (!string.IsNullOrEmpty(toEmailfield))
{
if (toEmailfield.Contains(','))
{
string[] emailAddresses = toEmailfield.Split(',');
foreach (string emailAddress in emailAddresses)
{
var toActivityParty = new ActivityParty();
toActivityParty.AddressUsed = emailAddress;
lstTo.Add(toActivityParty);
}
}
else
{
var toActivityParty = new ActivityParty();
toActivityParty.AddressUsed = toEmailfield;
lstTo.Add(toActivityParty);
}
}
// Add To, Cc and From users to email
email.From = new[] { fromParty }; //fromParty fromActivityParty
email.To = lstTo;
//email.Cc = lstTo;
// Set the case regarding
email.RegardingObjectId = new EntityReference(Incident.EntityLogicalName, caseEntity.Id);
// Create email
Guid emailId = service.Create(email); //This line is throwing exception.
SendEmailRequest sendRequest = new SendEmailRequest();
sendRequest.EmailId = emailId;
sendRequest.TrackingToken = string.Empty;
sendRequest.IssueSend = true;
tracingService.Trace("4");
// Send the email message.
service.Execute(sendRequest);
tracingService.Trace("5");