Question

I have created a plugin which reads the body (description) of the email. But it is giving me error when I try to read something from the plugin. It gives me NullReferenceException. I have registered the plugin on the creating of the new email activity (post-create). The subject field in the email entity is of Single Line of text but the email body(description) is multiple line of text. I am able to read the subject but not able to read email body. Below is the code I am using:

var body = email_entity["description"];

I guess that the e-mail body stores data in the form of string array. When I use the below piece of code but didn't assigned the value to any variable I got no errors.

var body = email_entity["description"];
string[] desc = (string[])body;

Now if I use desc[0] to set the value in a variable it throws me the same NullreferenceException.

I don't know how to read the value from the multiple lines of text field in a plugin. I tried above but it is of no use.

Does anyone has any idea what I am missing or doing wrong?

Thanks!

Was it helpful?

Solution

Multi-line text fields are strings, not arrays of strings. in the line:

var body = email_entity["description"];

body is of type string. The newline characters are in that string. if you want to conver that string into an array of strings for each newline character, try:

List<string> bodyLines = email_entity["description"].Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top