Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CRM Email with attachment

11 views
Skip to first unread message

Traci

unread,
May 10, 2006, 5:59:01 AM5/10/06
to
Hi

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

Patrick

unread,
May 10, 2006, 8:59:01 AM5/10/06
to
This is the bit to create an attactment:

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

Traci

unread,
May 10, 2006, 9:30:02 AM5/10/06
to
thank you

Do you perhaps have sample code for the email as well?
And how to link the email to the attachment?

Thanks

Patrick

unread,
May 10, 2006, 10:52:02 AM5/10/06
to
Code is below. The link between the email and the attachement is done via de
activityid of the email (email inherits from activity) this is the variable
emailId created at the end of this code bit. This is used at line 3 of the
previous bit of code.

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);

Traci

unread,
May 17, 2006, 5:47:01 AM5/17/06
to
Thanks

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?

Leonardo

unread,
Sep 13, 2006, 2:21:01 PM9/13/06
to
Hi guys,

I have the same problem, I can't send an email using a customized entity. Do
you have a solution for that?

Thanks

Niki

unread,
Dec 20, 2006, 2:37:01 AM12/20/06
to
dfd
0 new messages