Hi ,

In this Article I would like to explain how to insert image in Email Body .

  • First we need to publish our Image in IIS . Where we will use the url reference to get available of the Image .
  • You can directly copy paste the image inside Email body , by selecting the image which is available in iis and paste it in Email body .

Using  C#

  • Select particular Image  and copy the url and use like bellow code.
  • Eg:
  • onlin
   //published Image Url Link
   string crmModule = "<html> <img  src='http://www.bse-c.co.kr/image/CRM%20capabilities.png'  width='150' height='150'></html>";
  • You can also Display Image Which are Created in CRM as Web Resource.
  • Upload your image as Web resource in Crm and Copy the URl available at webresource bellow.

web

Use like bellow code,

//Uploaded Crm webresource Url.
string webresource = "<html> <img  src='~/WebResources/new_Crm'  width='205' height='150'></html>";
  • Refer Bellow Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//CRM SDK Namespace
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Crm.Sdk.Messages;

namespace Sample
{
    public class Email : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            // Obtain the execution context from the service provider.
            IPluginExecutionContext context =
            (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

            if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
            {

                Entity Lead = (Entity)context.InputParameters["Target"];
                string Emailid = Lead.GetAttributeValue<string>("emailaddress1");
                string Name = Lead.GetAttributeValue<string>("lastname");

                //From Current User
                Entity from = new Entity("activityparty");
                from["partyid"] = new EntityReference("systemuser", context.UserId);

                // To the Newly Created Lead User
                Entity to = new Entity("activityparty");
                to["partyid"] = new EntityReference("lead", Lead.Id);

                //Uploaded Crm webresource Url.
              string webresource = "<html> <img  src='~/WebResources/new_Crm'  width='205' height='150'></html>";

              //published Image Url Link

              string crmModule = "<html> <img  src='http://www.bse-c.co.kr/image/CRM%20capabilities.png'  width='150' height='150'></html>";

                //Hyperlink (or) Re-Direct Url link
              string Hyper = String.Format("<a href='https://parthimscrm.wordpress.com/'> Click Here</a>");

                //Create Email
             Entity Email  = new Entity("email");
             Email["from"] = new Entity[] { from };
             Email["to"] = new Entity[] { to };
             Email["subject"] = "welcome Mr : " + Name;
             Email["description"] = "<h3> Dear  " + Name + "</h3>" + "<br/>" + "Microsoft Dynamics CRM 2011 Module" + "<br/>" + crmModule + "<br/>" + "visit my wordpress blog " + Hyper + "<br/>" + webresource;

                //SendEmailRequest
                Guid _emailId = service.Create(Email);
                SendEmailRequest reqSendEmail = new SendEmailRequest();
                reqSendEmail.EmailId = _emailId;
                reqSendEmail.TrackingToken = "";
                reqSendEmail.IssueSend = true;
                SendEmailResponse res = (SendEmailResponse)service.Execute(reqSendEmail);

            }
        }
    }
}
  • Register your plugin Message = Create
  • Primary Entity = lead
  • Post Operation
  • 10

Hope This Help You . . . 

2 thoughts on “Display Images In Email body crm 2011

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s