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"); }