locked
Executing SendEmailRequest throws an exception. RRS feed

  • Question

  • Hi all,

    I am trying to create and send an email from a plugin using the SendEmailRequest. However, when executed it always throws an exception as some "An unexpected error occured. Server could not process the request. Platform error..."

    What could be wrong ? Please help !!

    Also, can the email router picks the email and sends it if I merely create a email activity and set its status as "Pending Send"?

    Thanks

    Monday, September 20, 2010 3:29 PM

Answers

  • I tried your above code. Works perfect by passing correct record id (systemuserid and email recipents)

    Ensure to check the creation of service and the credentials you had used.

    activityparty party = new activityparty();
    party.partyid = new Lookup("systemuser", myuserIdValue);

    email assignedemail = new email();
    assignedemail.description = MailBody;
    assignedemail.from = new activityparty[] { party };
    assignedemail.to = new activityparty[] { party };
    assignedemail.ownerid = new Owner("systemuser", myuserIdValue);
    assignedemail.directioncode = CrmTypes.CreateCrmBoolean(true);
    //assignedemail.regardingobjectid = new Lookup("mycustomentity", customId);
    assignedemail.subject = "sample subject";
    Guid emailid = CrmService.Create(assignedemail);

    SendEmailRequest request = new SendEmailRequest();
    request.EmailId = emailid;
    request.IssueSend = true;
    request.TrackingToken = "";
    CrmService.Execute(request); 

    Tuesday, September 21, 2010 9:41 AM

All replies

  • Try to use

    try

    {

    //your code here

    }

    catch(SoapException ex)

    {

    throw new Exception(ex.Detail.InnerText);

    }

     

    to get detailed exception.


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Monday, September 20, 2010 3:31 PM
    Moderator
  • I already have the exception handling in place and I am logging this error, where I found the error description.

    Any more clues ?

    Also, can the email router pick the email and send it, if I merely create a email activity and set its status as "Pending Send"?

    Tuesday, September 21, 2010 5:21 AM
  • Can you paste your code block so that we any check for any clues.
    Tuesday, September 21, 2010 6:32 AM
  •  

    // Below is the code block.
    
    try
    
    {
    
      email assignedemail = new email();
      assignedemail.description = MailBody;
      assignedemail.from = new activityparty[] { new activityparty() { partyid = new Lookup("systemuser", myuserIdValue) } };
      assignedemail.to = new activityparty[] { new activityparty() { partyid = new Lookup("systemuser", assignedIdValue)} };
      assignedemail.ownerid = new Owner("systemuser", myuserIdValue);
      assignedemail.directioncode = CrmTypes.CreateCrmBoolean(true);
      assignedemail.regardingobjectid = new Lookup("mycustomentity", customId);
      assignedemail.subject = "sample subject";
      Guid emailid = crmService.Create(assignedemail);
    
    
      SendEmailRequest request = new SendEmailRequest(); 
      request.EmailId = emailid;
      request.IssueSend = true;
      request.TrackingToken = "";
      crmService.Execute(request);
    
    }
    
    catch (SoapException sx) {
    
     if (isLogEnabled) {
    
     logEntry(logfilename, SOAP ERROR: " + sx.Message + " - " + sx.Detail.InnerText);
    
     }
    
    }
    Tuesday, September 21, 2010 6:46 AM
  • I think your problem is the context in which the crmService is instantiated. You're probably using SYSTEM user rather than myuserIdValue.
    Tuesday, September 21, 2010 8:48 AM
  • I tried your above code. Works perfect by passing correct record id (systemuserid and email recipents)

    Ensure to check the creation of service and the credentials you had used.

    activityparty party = new activityparty();
    party.partyid = new Lookup("systemuser", myuserIdValue);

    email assignedemail = new email();
    assignedemail.description = MailBody;
    assignedemail.from = new activityparty[] { party };
    assignedemail.to = new activityparty[] { party };
    assignedemail.ownerid = new Owner("systemuser", myuserIdValue);
    assignedemail.directioncode = CrmTypes.CreateCrmBoolean(true);
    //assignedemail.regardingobjectid = new Lookup("mycustomentity", customId);
    assignedemail.subject = "sample subject";
    Guid emailid = CrmService.Create(assignedemail);

    SendEmailRequest request = new SendEmailRequest();
    request.EmailId = emailid;
    request.IssueSend = true;
    request.TrackingToken = "";
    CrmService.Execute(request); 

    Tuesday, September 21, 2010 9:41 AM