I'm having some problems sending email programatically in CRM.
I also need to attach a report to the email.
Could someone please provide me with some sample code how to send a CRM
email with an attachment?
Thanks
Tracey
Crm.activitymimeattachment attachment = new
Crm30.Crm.activitymimeattachment();
attachment.attachmentnumber = Crm30.SdkHelpers.CrmTypes.CreateCrmNumber(1);
attachment.activityid = Crm30.SdkHelpers.CrmTypes.CreateLookup("email",
emailId);
attachment.subject = "filename.doc";
Guid attachementId = service.Create(attachment);
This uploads the actual file:
byte[] data = ....
Crm.UploadFromBase64DataActivityMimeAttachmentRequest uploadRequest = new
Crm.UploadFromBase64DataActivityMimeAttachmentRequest();
uploadRequest.ActivityMimeAttachmentId = attachementId;
uploadRequest.Base64Data = Convert.ToBase64String(data);
uploadRequest.FileName = "filename.doc";
uploadRequest.MimeType = .... ;
service.Execute(uploadRequest);
--
Patrick Verbeeten (MCSD)
Lead Developer
Aviva IT
Web: aviva-it.nl
Do you perhaps have sample code for the email as well?
And how to link the email to the attachment?
Thanks
Crm.email email = new Crm30.Crm.email();
email.ads_autosendmessage =
Crm30.SdkHelpers.CrmTypes.CreateCrmBoolean(false);
email.description = string.Format(mailTemplate.Body
, employeeProduct.productnumber,
siteInformation.address1_telephone1, siteInformation.emailaddress,
systemUser.firstname, systemUser.lastname, siteInformation.address1_city);
email.regardingobjectid =
Crm30.SdkHelpers.CrmTypes.CreateLookup("lead", leadId);
email.subject = mailTemplate.Subject;
Crm.activityparty from = new Crm30.Crm.activityparty();
from.partyid =
Crm30.SdkHelpers.CrmTypes.CreateLookup(Crm.EntityName.systemuser.ToString(),
systemUser.systemuserid.Value);
email.from = new Crm30.Crm.activityparty[] { from };
Crm.activityparty recipient = new Crm30.Crm.activityparty();
recipient.partyid =
Crm30.SdkHelpers.CrmTypes.CreateLookup(Crm.EntityName.lead.ToString(),
leadId);
email.to = new Crm30.Crm.activityparty[] { recipient };
Guid emailId = service.Create(email);
Eventually got it to work with a Lead object.
I cannot get the code to work for a custom object though.
The exception is thrown when creating the email activity:
"Cannot create activity party of specified object type."
Any ideas?
I have the same problem, I can't send an email using a customized entity. Do
you have a solution for that?
Thanks