Skip to content

Riyaz's Innovative Solutions Blog

Your one stop consultant for Digital Workplace

  • About

Cannot get the full name or e-mail address of user

February 7, 2015 ~ msmriyaz

If you are using Claim authentication, make sure to pass the login user name in the format of “@"i:0#.w|readylab\sheriffm"” for calling the method – “SPUtility.GetFullNameandEmailfromLogin”

Otherwise you will end up with an error – Cannot get the full name or e-mail address of user.

string displayName = ""; string emailAddress = ""; try { SPUtility.GetFullNameandEmailfromLogin(web, login, out displayName, out emailAddress); } catch (Exception ex) { Console.WriteLine("Unable to get user information."); Console.WriteLine("Error: "+ex.Message); Console.Write("Press any key..."); Console.ReadKey(); return; } Console.WriteLine("Display Name: {0}\nE-mail: {1}", displayName, emailAddress);

To send/Test email within SharePoint:

string subject = "Test message"; string body = "Testing app message"; MailServerInfo serverInfo = new MailServerInfo(spSite); string server = serverInfo.Server; string replyTo = serverInfo.ReplyTo; string from = serverInfo.From; Console.WriteLine(serverInfo.ServerInformation); Console.WriteLine("Trying to send e-mail via Sharepoint..."); if (!SPUtility.SendEmail(web, true, true, emailAddress, subject, body)) { Console.WriteLine("Error: Unable to send e-mail via Sharepoint"); Console.WriteLine("Trying via SMTP..."); SmtpClient client; try { client = new SmtpClient(server); } catch (Exception ex) { Console.WriteLine("Could not contact server"); Console.WriteLine("Error: " + ex.Message); Console.Write("Press any key..."); Console.ReadKey(); return; } try { client.Send(from, emailAddress, subject, body); } catch (Exception ex) { Console.WriteLine("Unable to send via SMTP client"); Console.WriteLine("Error: " + ex.Message); Console.Write("Press any key..."); Console.ReadKey(); return; } Console.WriteLine("E-mail has been sent successfully via SMTP client"); } else { Console.WriteLine("E-mail has been sent successfully via Sharepoint"); }

Share this:

  • Email
  • Print
  • Facebook
  • Reddit
  • Twitter

Like this:

Like Loading...

Related

Posted in .NET, Development, Environment, SharePoint-2010, SharePoint-2013 cannotclaime-mailemailencodedfull namegetGetFullNameandEmailfromLoginloginResolveSendEmailuser name

Published by msmriyaz

Software Solutions Architect. Passionate about helping organisations enabling innovative software solutions to drive adoption. View all posts by msmriyaz

Post navigation

‹ PreviousSet a web template’s welcome page URL declaratively without using the publishing feature
Next ›Add/Update SP (SharePoint) Site Quota Template using PowerShell

Recent Posts

  • NVM is a life saver when you want to work with multiple version of node.js
  • Online Unicode characters Reference
  • Innovative Enablement of UX Drives Adoption
  • The IT as a Utility
  • Creating and Configuring Resource Mailboxes

Author Grid

Top Clicks

  • nodejs.org/en/download/re…

myTweets

  • A scam text message from JB HIFI. #scam #jbhifi #textmessage @JBHiFi https://t.co/5neqI8D5EA 2 weeks ago
  • Do not install the #Mono framework dependent application on new #Apple #Macbook Air M1 Chip. it crashes Safari and… twitter.com/i/web/status/1… 2 weeks ago
  • Spending the day at Nelson Beach youtu.be/FtzaXU9cGn8 4 weeks ago
  • China will expand trials of its #digital yuan Friday evening with a feature letting individuals send #money to each… twitter.com/i/web/status/1… 1 month ago
  • Australia seems high too - The top tier income tax in rival cities Japan’s 45%. Hong Kong has a 17%, while Singapor… twitter.com/i/web/status/1… 1 month ago
Follow @msmriyaz

Search Topic

Follow Riyaz's Innovative Solutions Blog on WordPress.com

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 100 other followers

myRSS

  • RSS - Posts
  • RSS - Comments

myTags

2010 account Add administration application Azure Branding bulk Cloud collection configure configuring content create Custom Customization data view web part Date debug Development Document e-mail email enable environment Error feature FILE Hotfix information install invoke library List Manage Master page migration Navantis Office 365 Outbound Page path Permission Picture policy PowerShell provisioning PS Reference script Server service SharePoint SharePoint 2010 SharePoint Designer site site collection SMTP Solution template test tfs Tool Update user id utility v4.master versioning View Virtual Visual Studio Visual Studio 2010 web wsp xslt
Website Powered by WordPress.com.
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.
%d bloggers like this: