How to send email to People or group field user
People/Group field in SharePoint allow us to keep adding the existing user(s) or group(s) into the document library or list item. Let’s think, I have a list where one field name i.e. Assigned To (reviewer) is type of People/Group. Objective is when I assign someone to review the list item, and then an email notification needs to be fired up to that reviewer.
In other words, you have to find that person from the UserCollection list in SharePoint and send an email to that associated person.
Now once you assign one person on this field, you will found how the SharePoint display his/her name in the New/Edit OTB form and it is like DOMAIN\LOGINNAME. So if your domain name is SP-SERV and your name is Himadrish Laha, it will be looks like SP-SERV\Himadrish Laha.
Below the simple code I have used to fetch the string data and it returns me something else which I found in the debugging mode “1;#SP-SERV\\kiran” (here I have added user Kiran). When I have added my name it looks like “16;#SP-SERV\\Himadrish Laha“. String represent is kind of <UserID>;#<UserLoginName>.More difficult for you to work.
My initial thought is to split the string value and use the UserID. However latter I found this is not the actual UserID associated with the user, instead of this, it is kind of index ID associated with this user in SharePoint. So, if you try to use this ID as below, I bet you will found different user in SPUser object. So the following code is incorrect to trap actual user:
string UserAccount = _ListItem["Assigned To (Reviewer)"].ToString();
int UserID;
if (UserAccount.Trim() != string.Empty)
{
UserID = Convert.ToInt32(UserAccount.Substring(0, UserAccount.IndexOf(“;”)));
SPUser _SPUser = properties.OpenWeb().Users[UserID];
string UserEmail = _SPUser.Email.ToString();
}
What we have left now is only the login display name. Here is also one drawback to trap the user. This string is Login Display Name and it is not the LoginID. So if my login id is Himadrish.Laha and my display name is Himadrish Laha, it will show me Himadrish Laha in the People filed control text box. Note the missing of the DOT (.). For people having same string in loginID as well as Login Display name shouldn’t be a problem, but for other it will make a big difference.
To resolve this issue, the following code may help you. In most of the cases, you can simply add one DOT (.) in between user’s given name and his/her family name. Inside the code, the web represent the SPWeb object. So the method is being used here is SPWeb.EnsureUser(). You need to pass user’s login id over there, and it will return you SPUser object.
string UserAccount = _ListItem["Assigned To (Reviewer)"].ToString();
string UserLogin;
string UserEmail = string.Empty;
if (UserAccount.Trim() != string.Empty)
{
UserLogin = UserAccount.Substring(UserAccount.IndexOf(“#”), (UserAccount.Length – UserAccount.IndexOf(“#”)));
UserLogin = UserLogin.Replace(“#”, “”).Replace(“;”, “”);
UserLogin = @”SP-SERV\” + UserLogin.Replace(” “,”.”);
SPUser _SPUser = web.EnsureUser(UserLogin);
UserEmail = _SPUser.Email.ToString();
_SPUser = null;
}
Kindly note, the above code may need to change according to get the login id from the login name. If in your organization the login id is something the first character of your given name i.e. H for Himadrish and then your last name i.e. Laha, then your login id would be HLAHA. So you need to change the above code and found the actual login id what it would be. Rest of the line would be same.
Hopes this will help you.


I collected so many interesting things in your blog especially its discussion. From the tons of comments on your posts, I think I am not the only one having all of the enjoyment here! continue the good work.Regards
Great blog here i like all the information thats being shared, congratulations.
That completely makes sense when you put it in that way. You actually cleared things up for me personally.
Thank you for the amazing post, I actually really liked it!! I added this specific internet page and I’m going to make sure to revisit.
First time commentor to this blog and just googled in. I like the design of this site. I just saved it, so you now have a follower!
Thank you!
That makes sense.
I’d have to buy into with you here. Which is not something I typically do! I love reading a post that will make people think. Also, thanks for allowing me to comment!
I’m still learning from you, as I’m improving myself. I absolutely love reading everything that is written on your site.Keep the tips coming. I liked it!
Great, this is simple tips and easy to understand. Thanks for share this post next I will always go here future for your update.
Cool information it is without doubt. We’ve been waiting for this content
Wow, great post Thanks for sharing !
kinda like the post you have written . it just isn’t that easy to find great text toactually read (you know READ! and not simply going through it like some uniterested and flesh eating zombie before going somewhere else), so cheers man for not wasting my time on the god forsaken internet.
Great post!
I love this blog layout One of the best I’ve seen.
Extremely cool, some wonderful points! I appreciate you making this article available, the rest of your site is also well done. I hope you have a great day.
Your framework is valueble forwards other self. Thanks!…
I am extremely a new comer to the internet and required to review this subject. Thought it was a great article very well written and helpful. I’ll definitely be coming back for your site to read more articles when i loved this one..
I completely agree with most of the ideas you’ve presented in this blog. They’re especially convincing and will most likely work. Could you please extend on this a bit more next time?
I find myself coming to your blog more and more often to the point where my visits are almost daily now!
I was pretty pleased to discover this web-site.I want to thanks for your precious time with this amazing learn!! I positively taking advantage of any little it and I’ve you book marked to look at brand-new stuff you writing.
This is WordPress blog application. You can get it in Google
Thanks for the post.