web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Retrieve attachments from Quote and send it through Email : Plugin

(0) ShareShare
ReportReport
Posted on by

Hello,

I need to retrieve the attachments from notes in the quote entity and attach it to a email and send it through an email using plugin. Also Should it be on postquoteUpdate ??

need help.

Thanks.

*This post is locked for comments

I have the same question (0)
  • anilambadan Profile Picture
    1,160 on at

    Please refer the following link it will give you the idea for downloading the attachments

    msdn.microsoft.com/.../gg328429.aspx

    thanks

    Anil

  • Rajkumar Rajaraman Profile Picture
    on at

    Hello,

    Refer the following links:

    mahenderpal.wordpress.com/.../sending-email-with-entity-attachment-from-notes

    community.dynamics.com/.../how-to-download-the-attachment-of-a-note-within-a-plugin-in-dynamics-crm

    Hope this helps.

    Regards,

    R.Rajkumar

    "Please mark my answer as verified if you found it helpful"

  • Mahendar Pal Profile Picture
    45,095 on at

    When you want to do it ? at the time of attachment is done ?? then you need to write a plugin on annotation (notes) and need to check for regardingobjectid if it is related to quote then you can download and send email with attachment.

  • Community Member Profile Picture
    on at

    Updated with Code. When an attachment is attached on quote i want that to be attached to email as well, i dont want it to be downloaded to my machine

                   Entity entity = (Entity)localContext.PluginExecutionContext.InputParameters["Target"];

                   if (entity.LogicalName != "quote")

                       return;

                   try

                   {

                       Quote quote = entity.ToEntity<Quote>();

                       if (quote.Attributes.Contains("ownerid") && quote.Attributes["ownerid"] != null)

                       {

                            ownerId = ((EntityReference)quote.Attributes["ownerid"]).Id;

                       }

                       localContext.Trace("ownerid" + ownerId);

                       if (quote.Attributes.Contains("customerid") && quote.Attributes["customerid"] != null)

                       {

                            custId = ((EntityReference)quote.Attributes["customerid"]).Id;

                       }

                       localContext.Trace("custid" + custId);

                       Entity fromParty = new Entity("activityparty");

                       fromParty["partyid"] = new EntityReference("systemuser", ownerId);

                       Entity toParty = new Entity("activityparty");

                       toParty["partyid"] = new EntityReference("account", custId);

                       Entity Email = new Entity("email");

                       Email.Attributes["from"] = new Entity[] { fromParty };

                       Email.Attributes["to"] = new Entity[] { toParty };

                       Email.Attributes["subject"] = "Annual Sales Report";

                       Email.Attributes["regardingobjectid"] = new EntityReference("quote", quote.Id);

                       Email.Attributes["ownerid"] = new EntityReference("systemuser", ownerId);

                       localContext.Trace("Creating email records" );

                       Guid EmailId = localContext.OrganizationService.Create(Email);

                       localContext.Trace("EmailId =" + EmailId);

                       QueryExpression queryExpressionForAnnotation = new QueryExpression()

                       {

                           EntityName = Annotation.EntityLogicalName,

                           ColumnSet = new ColumnSet(true),

                           Criteria = new FilterExpression

                           {

                               Conditions =

                               {

                                   new ConditionExpression{

                                       AttributeName = "ObjectId",

                                       Operator = ConditionOperator.Equal,

                                       Values ={quote.Id}

                                      },

                                   new ConditionExpression{

                                       AttributeName = "statecode",

                                       Operator = ConditionOperator.Equal,

                                       Values ={"Active"}

                                   }

                               }

                           },

                           TopCount = 1,

                           Orders ={

                                      new OrderExpression{

                                          AttributeName = "createdon",

                                          OrderType = OrderType.Descending

                                      }

                                   }

                       };

                       localContext.Trace("Annnotation records " );

                       List<Entity> Annotationcollection = localContext.OrganizationService.RetrieveMultiple(queryExpressionForAnnotation).Entities.ToList();

                       Annotationcollection.ForEach(a =>

                       {

                           Annotation annotation = a.ToEntity<Annotation>();

                           ActivityMimeAttachment ama = new ActivityMimeAttachment();

                           ama.Subject = annotation.Subject;

                           string filename = "Report.pdf";

                           ama.FileName = filename;

                           byte[] filestream = new byte[] { };

                           ama.Body = Convert.ToBase64String(filestream);

                           ama.MimeType = "text/plain";

                           ama.AttachmentNumber = 1;

                           ama.ObjectId = new EntityReference(Email.LogicalName, EmailId);

                           localContext.Trace("creating Attachments");

                           Guid? guid = localContext.OrganizationService.Create(ama);

                           localContext.Trace("Attachment"+ama);

                       });

                       SendEmailRequest req = new SendEmailRequest();

                       req.EmailId = EmailId;

                       req.IssueSend = true;

                       req.TrackingToken = "";

                       SendEmailResponse res = (SendEmailResponse)localContext.OrganizationService.Execute(req);

                   }

                   catch (FaultException ex)

                   {

                       throw new InvalidPluginExecutionException("error", ex);

                   }

    //error

    [Microsoft.Xrm.Sdk.Workflow: Microsoft.Xrm.Sdk.Workflow.Activities.UpdateEntity]

    [UpdateStep5]

    Able to trace till 'Creating email records'

    after that its failing.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Varsha deshpande Profile Picture

Varsha deshpande 5

#2
JS-09031509-0 Profile Picture

JS-09031509-0 3

#3
Ciprian  P Profile Picture

Ciprian P 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans