CRM 3.0 SDK Email Attatchemnt Problem. RRS feed

  • Question

  • I wonder if anyone can help,


    I use the following code to create multiple attachments in a CRM email, but when the attachment list holds more than 5 attachments and you try and send the email from within CRM, you get the error: Unexpected Error.


    If I then remove attachments from the list to only leave 5 it sends. I have removed attachments in many different orders so it is not one particular attachment that causes the problem.


    I am using CRM SDK 3.0.7 and have rollup 2 of the CRM installed.


    This is my code:


    int ctr = 1;


    foreach (FileAttachment FileAttachment in AttatchedFiles)



    //Add an attachment

         // Create a new Attachment object. 

         // Attach it to the email. 

         activitymimeattachment attachment = new activitymimeattachment();

         attachment.activityid = new Lookup();

         attachment.activityid.Value = emailID;

         attachment.activityid.type = EntityName.email.ToString();



         attachment.attachmentnumber = new CrmNumber();

         attachment.attachmentnumber.Value = ctr;


         // Create the Attachment in CRM. 

         Guid attachmentId = pCrmService.Create(attachment);


         // Get a pointer to the file and open up a stream

         FileInfo pointer = new FileInfo(FileAttachment.FileName);

         FileStream fileStream = pointer.OpenRead();


         // Encode the data using base64

         byte[] byteData = new byte[(int)fileStream.Length];

         fileStream.Read(byteData, 0, (int)fileStream.Length);

         string encodedData = System.Convert.ToBase64String(byteData);


         //close the stream.





         // Create the request object to upload the file to CRM.

         UploadFromBase64DataActivityMimeAttachmentRequest upload = new UploadFromBase64DataActivityMimeAttachmentRequest();



    // Set the properties of the request object.

         upload.ActivityMimeAttachmentId = attachmentId;

         upload.FileName = FileAttachment.FileName;

         upload.MimeType = "application/octet-stream";

         upload.Base64Data = encodedData;


         // Upload the file to CRM. 

         UploadFromBase64DataActivityMimeAttachmentResponse uploaded = (UploadFromBase64DataActivityMimeAttachmentResponse)pCrmService.Execute(upload);










    • Moved by Max Wang_1983 Tuesday, April 26, 2011 6:15 PM forum consolidation (From:Architecture, Tools, and Process for ISVs)
    Thursday, September 27, 2007 1:37 PM