public void sendEmail(string useremail, string subject, string messagebody, string username, string pwd, string serverip, int portno, string fromemailid) { SSAErrorLog logObj = new SSAErrorLog(); try { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient(serverip); mail.From = new MailAddress(fromemailid); mail.To.Add(useremail); mail.Subject = subject; mail.Body = messagebody; SmtpServer.Port = portno; if (!username.Equals("none")) { SmtpServer.Credentials = new System.Net.NetworkCredential(username, pwd); } SmtpServer.UseDefaultCredentials = false; // SmtpServer.EnableSsl = true; SmtpServer.Send(mail); } catch (Exception er) { logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "Error while sending mail " + er.Message); } }
public string IsAuthenticatedStr(string domain, string username, string pwd) { string domainAndUsername = domain + @"\" + username; string displayName = null; DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd); //System.IO.File.WriteAllText(@"C:\SelfServiceAdminstration\log2.txt", "domain " + domain + "username " + username); Hashtable getDataHash = null; SSAErrorLog logObj = new SSAErrorLog(); try { //Bind to the native AdsObject to force authentication. object obj = entry.NativeObject; DirectorySearcher search = new DirectorySearcher(entry); logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "locked ?? 2 >> " + entry.Properties["LockOutTime"].Value); // entry.Properties["LockOutTime"].Value = 0; // entry.CommitChanges(); logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "locked ?? 3 >> "); search.Filter = "(SAMAccountName=" + username + ")"; logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "locked ?? 4 >> "); search.PropertiesToLoad.Add("cn"); SearchResult result = search.FindOne(); logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "locked ?? 5 >> " + result); // System.IO.File.WriteAllText(@"C:\SelfServiceAdminstration\log6.txt", "result.Properties.Count " + result.Properties.Count); DirectoryEntry userentry = result.GetDirectoryEntry(); if (null == result) { return(null); } //Update the new path to the user in the directory. _path = result.Path; logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "locked ?? 6 >> " + _path); //System.IO.File.WriteAllText(@"C:\SelfServiceAdminstration\log3.txt", "result.Path " + result.Path); displayName = (string)result.Properties["cn"][0]; logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "locked ?? 7 >> " + displayName); //System.IO.File.WriteAllText(@"C:\SelfServiceAdminstration\log4.txt", "result.displayName " + displayName); // getDataHash = GetUserInfo(displayName, result.Path); // userentry.Invoke("SetPassword", new object[] { "ooty@4567" }); // userentry.Properties["LockOutTime"].Value = 0; userentry.Close(); } catch (Exception ex) { //System.IO.File.WriteAllText(@"C:\SelfServiceAdminstration\log5.txt", ex.Message + " stack "+ ex.StackTrace ); throw new Exception("Error authenticating user. " + ex.Message); } return(displayName); }