/// <summary> /// Date Created: 10/11/2011 /// Created By: Josephine Gad /// (description) Send Email /// -------------------------------------- /// Date Modified: 06/Dec/2012 /// Created By: Josephine Gad /// (description) Add security to email address by using encrypt/decrypt /// Get the email credentials from web config /// Use also the SHRSS Spport email from web config /// -------------------------------------- /// </summary> /// <param name="sFrom"></param> /// <param name="sTo"></param> /// <param name="sSubject"></param> /// <param name="sMessage"></param> public static void SendEmail(string sFrom, string sTo, string sSubject, string sMessage) { try { string sPassphrase = "Great Vacations Begin With Great Employees!"; string sUser = DecryptString(ConfigurationSettings.AppSettings["TravelmartMailUser"].ToString(), sPassphrase); string sPwd = DecryptString(ConfigurationSettings.AppSettings["TravelmartMailPassword"].ToString(), sPassphrase); string sEmail = ConfigurationSettings.AppSettings["RCCLSupportEmail"].ToString(); if (sTo != "") { string sServer = ConfigurationSettings.AppSettings["TravelmartMailServer"].ToString(); int iPort = GlobalCode.Field2Int(ConfigurationSettings.AppSettings["TravelmartMailPort"]); sFrom = sEmail; MailAddress emailFrom = new MailAddress(sFrom); MailAddress emailTo = new MailAddress(sTo); //MailMessage emailMsg = new MailMessage(emailFrom, emailTo); using (MailMessage emailMsg = new MailMessage(emailFrom, emailTo)) { emailMsg.Subject = sSubject; emailMsg.IsBodyHtml = true; emailMsg.Body = sMessage; SmtpClient emailClient = new SmtpClient(sServer, iPort); emailClient.Credentials = new System.Net.NetworkCredential(sUser, sPwd); emailClient.EnableSsl = true; emailClient.Send(emailMsg); } } } catch (Exception ex) { throw ex; } }
/// <summary> /// Date Created: 14/11/2011 /// Created By: Josephine Gad /// (description) Send Email with attachment /// -------------------------------------------------------------------------------------------------------------- /// Date Modified: 24/02/2012 /// Modified By: Charlene Remotigue /// (description) Send multiple attachments /// -------------------------------------------------------------------------------------------------------------- /// Date Modified: 27/03/2012 /// Modified By: Gabriel Oquialda /// (description) Send multiple recipient and cc /// -------------------------------------------------------------------------------------------------------------- /// Date Modified: 29/03/2012 /// Modified By: Gabriel Oquialda /// (description) Added configuration settings/appsettings key for smtp network username and password (encrypted) /// Added md5 decryption for encrypted smtp network username and password /// -------------------------------------- /// Date Modified: 06/Dec/2012 /// Created By: Josephine Gad /// (description) Get the email credentials from web config /// -------------------------------------- /// </summary> /// <param name="sFrom"></param> /// <param name="sTo"></param> /// <param name="sCc"></param> /// <param name="sSubject"></param> /// <param name="sMessage"></param> /// <param name="attachment"></param> public static void SendEmailWithAttachment(string sFrom, string sTo, string sCc, string sSubject, string sMessage, string attachment) { char[] charsToTrim = { ';' }; string sTos = sTo.TrimEnd(charsToTrim); string sCcs = sCc.TrimEnd(charsToTrim); string[] attachments = attachment.Split(';'); string[] recipients = sTos.Split(';'); string[] carboncopy; try { // Encryption (for debugging purpose only) //string EncryptedNetworkUser = EncryptString(TravelmartNetworkUser, TravelmartPassphrase); //string EncryptedNetworkPass = EncryptString(TravelmartNetworkPass, TravelmartPassphrase); // Decryption //string DecryptedNetworkUser = DecryptString(TravelmartNetworkUser, TravelmartPassphrase); //string DecryptedNetworkPass = DecryptString(TravelmartNetworkPass, TravelmartPassphrase); if (sTo != "") { string sPassphrase = "Great Vacations Begin With Great Employees!"; string sUser = DecryptString(ConfigurationSettings.AppSettings["TravelmartMailUser"].ToString(), sPassphrase); string sPwd = DecryptString(ConfigurationSettings.AppSettings["TravelmartMailPassword"].ToString(), sPassphrase); string sEmail = ConfigurationSettings.AppSettings["RCCLSupportEmail"].ToString(); string sEmailDisplay = ConfigurationSettings.AppSettings["RCCLSupportEmailDisplay"].ToString(); string sServer = ConfigurationSettings.AppSettings["TravelmartMailServer"].ToString(); int iPort = GlobalCode.Field2Int(ConfigurationSettings.AppSettings["TravelmartMailPort"]); bool isEnableSSL = GlobalCode.Field2Bool(ConfigurationSettings.AppSettings["EnableSSL"]); sFrom = sEmail; MailMessage emailMsg = new MailMessage(); emailMsg.From = new MailAddress(sFrom, sEmailDisplay); for (int i = 0; i < recipients.Length; i++) { MailAddress emailTo = new MailAddress(recipients[i]); emailMsg.To.Add(emailTo); } if (sCcs != "") { carboncopy = sCcs.Split(';'); for (int i = 0; i < carboncopy.Length; i++) { MailAddress emailCc = new MailAddress(carboncopy[i]); emailMsg.CC.Add(emailCc); } } for (int i = 0; i < attachments.Length; i++) { Attachment data = new Attachment(attachments[i], MediaTypeNames.Application.Octet); emailMsg.Attachments.Add(data); } emailMsg.Subject = sSubject; emailMsg.IsBodyHtml = true; emailMsg.Body = sMessage; //details from web config //SmtpClient emailClient = new SmtpClient(); //emailClient.Host = "mail.ptc.com.ph"; //emailClient.Host = ConfigurationSettings.AppSettings["TravelmartMailServer"].ToString(); SmtpClient emailClient = new SmtpClient(sServer, iPort); emailClient.Credentials = new System.Net.NetworkCredential(sUser, sPwd); emailClient.EnableSsl = isEnableSSL; emailClient.Send(emailMsg); } } catch (Exception ex) { throw ex; } }
/// <summary> /// Date Created: 18/08/2011 /// Created By: Josephine Gad /// Description: Get login role /// -------------------------------- /// Date Modified: 27/10/2011 /// Modified By: Josephine Gad /// Description: get the primary role of the user /// </summary> public static string GetUserRole() { //return Roles.GetRolesForUser(GetUserName())[0]; return(GlobalCode.Field2String(HttpContext.Current.Session["UserRole"])); }
public static List <UserList_LDAP> GetLDAPUser(string sEmail) { List <UserList_LDAP> list = new List <UserList_LDAP>(); string sCompany; using (System.Net.WebClient client = new System.Net.WebClient()) { string sAPI = MUser.GetLDAP(); client.Headers.Add("content-type", "application/json");//set your header here, you can add multiple headers //verify if the username exist in LDAP string sResult = client.DownloadString(sAPI + "search?user="******",{".ToCharArray()); foreach (var arrayValue in ArrayResult) { var key = arrayValue.Key; var value = arrayValue.Value; if (key == "status") { if (GlobalCode.Field2String(value).ToLower() == "true") { } else { break; } } else if (key == "result") { if (value != null) { ArrayResultChild = (Dictionary <string, object>)value; foreach (var ResultChild in ArrayResultChild) { var resultChildKey = ResultChild.Key; var resultChildValue = ResultChild.Value; //if (resultChildKey == "entries") //{ // if (resultChildValue != null) // { // ArrayResultEntries = (Dictionary<string, object>)resultChildValue; // foreach (var resultEntries in ArrayResultEntries) // { // if (resultEntries.Key == "uid") // sUserName = GlobalCode.Field2String(resultEntries.Value); // } // } //} if (resultChildKey == "member") { if (resultChildValue != null) { var arrCompanyValue = (ArrayList)resultChildValue;//(List<string>)resultChildValue; for (var i = 0; i < arrCompanyValue.Count; i++) { if (GlobalCode.Field2String(arrCompanyValue[i]) == MUser.GetLDAPCompany()) { sCompany = GlobalCode.Field2String(GlobalCode.Field2String(arrCompanyValue[i])); } } } } } } } } } return(list); }
/// <summary> /// Date Created: 28/Oct/2015 /// Created By: Josephine Monteza /// (description) Add/Edit user from LDAP /// </summary> public static string AddEditUserFromLDAP(string strUsername, string strFName, string strLName, string strEmail, string strPWD, string sType, string strEmailNew) { string sReturn = ""; try { using (System.Net.WebClient client = new System.Net.WebClient()) { string sAPI = MUser.GetLDAP(); client.Headers.Add("content-type", "application/json");//set your header here, you can add multiple headers //verify if the username exist in LDAP string sResult = client.DownloadString(sAPI + "search?user="******",{".ToCharArray()); string sUserName = ""; string sCompany = ""; //bool IsExistinLDAP = false; foreach (var arrayValue in ArrayResult) { var key = arrayValue.Key; var value = arrayValue.Value; if (key == "status") { if (GlobalCode.Field2String(value).ToLower() == "true") { sUserName = strUsername; } else { break; } } else if (key == "result") { if (value != null) { ArrayResultChild = (Dictionary <string, object>)value; foreach (var ResultChild in ArrayResultChild) { var resultChildKey = ResultChild.Key; var resultChildValue = ResultChild.Value; //if (resultChildKey == "entries") //{ // if (resultChildValue != null) // { // ArrayResultEntries = (Dictionary<string, object>)resultChildValue; // foreach (var resultEntries in ArrayResultEntries) // { // if (resultEntries.Key == "uid") // sUserName = GlobalCode.Field2String(resultEntries.Value); // } // } //} if (resultChildKey == "member") { if (resultChildValue != null) { var arrCompanyValue = (ArrayList)resultChildValue;//(List<string>)resultChildValue; for (var i = 0; i < arrCompanyValue.Count; i++) { if (GlobalCode.Field2String(arrCompanyValue[i]) == MUser.GetLDAPCompany()) { sCompany = GlobalCode.Field2String(GlobalCode.Field2String(arrCompanyValue[i])); } } } } } } } } client.Headers.Add("content-type", "application/json");//set your header here, you can add multiple headers client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; //if user exist in LDAP TM, do not do anything if (strUsername == sUserName && sCompany == MUser.GetLDAPCompany()) { //Update user string sEditUser = sAPI + "modify"; string sParameter = "user="******"&firstname=" + strFName; //sParameter = sParameter + "&middlename=" + ""; //sParameter = sParameter + "&lastname=" + strLName; //sParameter = sParameter + "&description=EditedFromTravelmartSite"; //sParameter = sParameter + "&active=1"; //sResult = client.UploadString(sEditUser, sParameter); //Update Email sEditUser = sAPI + "changemail"; sParameter = "user="******"&email=" + strEmailNew; client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; sResult = client.UploadString(sEditUser, sParameter); sResultArray = sResult.Split(",{".ToCharArray()); string[] sSuccessArray; string sSuccessfull; for (int i = 0; i < sResultArray.Count(); i++) { if (sResultArray[i].Contains("\"message\"")) { sSuccessArray = sResultArray[i].Split(":".ToCharArray()); sSuccessfull = sSuccessArray[1].Replace("\"", ""); sReturn = sSuccessfull.Replace("}", ""); } } sReturn = " User Edit: " + sReturn; } //if user exist but no TM app, password is blank else if (strUsername == sUserName && sCompany != MUser.GetLDAPCompany()) { string sAddUser = sAPI + "add"; string sParameter = "user="******"&pass="******"&email=" + strEmail; sParameter = sParameter + "&firstname=" + strFName; sParameter = sParameter + "&middlename=" + ""; sParameter = sParameter + "&lastname=" + strLName; sParameter = sParameter + "&description=AddedFromTravelmartSite"; sParameter = sParameter + "&company=" + MUser.GetLDAPCompany(); sResult = client.UploadString(sAddUser, sParameter); sResultArray = sResult.Split(",{".ToCharArray()); string[] sSuccessArray; string sSuccessfull; for (int i = 0; i < sResultArray.Count(); i++) { if (sResultArray[i].Contains("\"message\"")) { sSuccessArray = sResultArray[i].Split(":".ToCharArray()); sSuccessfull = sSuccessArray[1].Replace("\"", ""); sReturn = sSuccessfull.Replace("}", ""); } } sReturn = " User Add with Other App: " + sReturn; } else { if (sType == "Edit") { MembershipUser mUser = Membership.GetUser(strUsername); string sPassword = DateTime.Now.ToLongTimeString().Replace(" ", "").Replace(":", ""); strPWD = sPassword; } string sAddUser = sAPI + "add"; string sParameter = "user="******"&pass="******"&email=" + strEmail; sParameter = sParameter + "&firstname=" + strFName; sParameter = sParameter + "&middlename=" + ""; sParameter = sParameter + "&lastname=" + strLName; sParameter = sParameter + "&description=FirstAddedFromTravelmartSite"; sParameter = sParameter + "&company=" + MUser.GetLDAPCompany(); sResult = client.UploadString(sAddUser, sParameter); sResultArray = sResult.Split(",{".ToCharArray()); string[] sSuccessArray; string sSuccessfull; for (int i = 0; i < sResultArray.Count(); i++) { if (sResultArray[i].Contains("\"message\"")) { sSuccessArray = sResultArray[i].Split(":".ToCharArray()); sSuccessfull = sSuccessArray[1].Replace("\"", ""); sReturn = sSuccessfull.Replace("}", ""); } } sReturn = " User Add New User: "******" - " + ex.Message; throw ex; } finally { sReturn = ""; } }