Skip to main content

Creating Email through Plugin / SDK in CRM 4 - line breaks don't work

You may have noticed when you create email using a sample code like below in a plugin or for that matter any other SDK based assembley for MS CRM. Your line breaks : \n or \r or System.Environment.NewLine will not work.

          email Email = new email();   
            = new activityparty[] { toParty };
                     Email.from = new activityparty[] { fromParty };
                     Email.regardingobjectid = regardingObject;
                     Email.subject = "Hello!!";
                     Email.description = "Dear, line 1" +         
                      "my message for your - line 2";
                     Email.directioncode = new CrmBoolean();
                     Email.directioncode.Value = true;
                     Guid _emailId = _service.Create(Email);
                     SendEmailRequest sendEmailRequest = new SendEmailRequest();
                     sendEmailRequest.EmailId = _emailId;
                     sendEmailRequest.TrackingToken = "";
                     sendEmailRequest.IssueSend = true;

I went into the business entity object that service will return when you query existing Emails in MSCRM, the .description field will have value like HTML rich text code :

.description = " < FONT size=2 face= \"Tahoma, Verdana, Arial \ " >your text < br / >"

So the key is to add "< br / >" as line feed instead of the common dot net and javascript carriage returns and you will be able to format your emails as you want from inside SDK plugins and more.


Ross said…
Can you show an example of where you put the
in your code above?
hero said…
Hi Ross,
Sorry not at the moment but if you have a large email body with many paragraphs you can see how line breaks work.
This article was very helpful in answering alot of questions.Thanks for posting.
Anonymous said…
nicely written article about CRM India
Harsh Vardhan said…
This is a really authentic and informative blog. Share more posts like this.
Openspan Online Training
Openstack Online Training
Openstack Online Course
jeya sofia said…
Excellent Blog, I like your blog and It is very informative. Thank you
OpenStack in Business

Meera Renjith said…
I read this blog, a Nice article...Thanks for sharing and waiting for the next...
Software Testing Training in Chennai
Software Testing Course in Chennai
Silviya26 said…
Fair valuable substance. Appreciation for sharing the critical information.

Swift Developer Training in Chennai
Learn Swift Online
Swift Training in Bangalore

Popular posts from this blog

Microsoft reuse windows media player toolbar in Windows 7

Those who have been using Windows Media Player would have experienced one thing over time, when you click on the little up-down arrow heads on the right, you could see a thumbnail live view of the current movie you were playing. This had been since Window XP and now Microsoft have copy-pasted this code to show live preview of each taskbar window like a folder, browser session, office documents and every possible item you can open and appear in task bar.  Those of you who haven't seen Windows 7, this is how taskbar preview looks like :

Cancel Workflow job programmatically - CRM v.4

How many times you had to created a workflow on some date like Due date which keeps changing as per client's request. While this may sound simple in business, on CRM you have a workflow that may be waiting till this date and send a reminder exactly a week before. So you need to keep calling this workflow every time the date is updated, to make the matters more complicated, all the previous jobs that had initiated due to past modification will keep running and chasing that date which is never going to occur. What you do now, manually cancel those to save system resources and stop the never ending system jobs. There is a way to do it through SDK, in my case I call this function as a custom workflow activity in the first step of the workflow which Cancels any previous jobs of this workflow.   #region Cancel My WFs             QueryExpression qe = new QueryExpression();             qe.EntityName = EntityName.asyncoperation.ToString();             ColumnSet cs = new

Capture and Handle event when one entity record is attached through a Many to Many relationship - MS CRM 4

If you have already dug up too much about trying to capture the event when an entity record in MS CRM is attached ~ linked to a record in many to many relationship. For example, if you have two entities : Supplier and Company in MS CRM where a supplier can do business with many companies and at the same time a Company can order stuff from many suppliers. What if you want to send some notification whenever a new supplier or an existing supplier is linked to a company; similarly you may want to send a notification when a Supplier signs a deal with 2-3 companies and gets linked to those. Some experts from MS CRM fraternity have suggested some ways to over ride this limitation of MS CRM that it does not expose any event for the above mentioned scenario, below is one of the examples: But making changes to the default plugin model of MS CRM to add Associate or Disassociate event is not so eas