/*Description: */ private void GetMails(string source) { string htmlMatch = TextUtils.GetPageSource(source); if (string.IsNullOrEmpty(htmlMatch)) { return; } Regex t = new Regex(@"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"); foreach (Match match in t.Matches(htmlMatch)) { if (TextUtils.ValidateMail(match.Value)) { string email = match.Value.Trim().ToLower(); EmailRow emailRow = BLL.GetEmail(email); if (emailRow == null) { CreateEmail(email); } } } }
public void SendEmailToUser(EmailUser user, EmailTypeOptions emailTypes) { var templateFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "" + SystemSettings.EmailTemplatePath + "\\" + emailTypes + ".html"); var templateText = FileHelper.ReadAllLines(templateFilePath); var eMailMessage = new EmailMessage(); var from = new EmailAddress { DisplayName = SystemSettings.SmtpSenderName, Address = SystemSettings.SmtpSenderMail }; eMailMessage.To = new List <EmailAddress> { new EmailAddress { Address = user.Email } }; string eMailSubject; var emailRow = new EmailRow(); var emailKeys = new List <EmailKey> { new EmailKey { Key = EmailKeyOptions.ApplicationName, Value = Dictionaries.ApplicationName }, new EmailKey { Key = EmailKeyOptions.ApplicationUrl, Value = SystemSettings.ApplicationUrl }, new EmailKey { Key = EmailKeyOptions.FirstName, Value = user.FirstName } , new EmailKey { Key = EmailKeyOptions.LastName, Value = user.LastName } }; switch (emailTypes) { case EmailTypeOptions.Add: { eMailSubject = Dictionaries.UserInformation; emailKeys.Add(new EmailKey { Key = EmailKeyOptions.Username, Value = user.Username }); emailKeys.Add(new EmailKey { Key = EmailKeyOptions.Password, Value = user.Password }); break; } case EmailTypeOptions.SignUp: { eMailSubject = Dictionaries.UserInformation; emailKeys.Add(new EmailKey { Key = EmailKeyOptions.Username, Value = user.Username }); emailKeys.Add(new EmailKey { Key = EmailKeyOptions.Password, Value = user.Password }); emailKeys.Add(new EmailKey { Key = EmailKeyOptions.ActivationCode, Value = (user.Id + "@" + user.CreateDate).Encrypt() }); break; } case EmailTypeOptions.ForgotPassword: { eMailSubject = Dictionaries.NewPassword; emailKeys.Add(new EmailKey { Key = EmailKeyOptions.Username, Value = user.Username }); emailKeys.Add(new EmailKey { Key = EmailKeyOptions.Password, Value = user.Password }); break; } case EmailTypeOptions.Update: { eMailSubject = Dictionaries.UserInformation; break; } case EmailTypeOptions.UpdateMyPassword: { eMailSubject = Dictionaries.NewPassword; emailKeys.Add(new EmailKey { Key = EmailKeyOptions.Username, Value = user.Username }); emailKeys.Add(new EmailKey { Key = EmailKeyOptions.Password, Value = user.Password }); break; } case EmailTypeOptions.UpdateMyInformation: { eMailSubject = Dictionaries.UserInformation; break; } default: { throw new ArgumentOutOfRangeException(nameof(emailTypes), emailTypes, null); } } emailKeys.Add(new EmailKey { Key = EmailKeyOptions.Subject, Value = eMailSubject }); emailRow.EmailKeys = emailKeys; eMailMessage.Subject = eMailSubject; eMailMessage.From = from; eMailMessage.IsBodyHtml = true; eMailMessage.Priority = EmailPriorityOptions.Normal; eMailMessage.Body = ConvertTemplateToString(templateText, emailRow); _smtp.Send(eMailMessage); }
private static string ConvertTemplateToString(string emailTemplate, EmailRow emailRow) { return(emailRow.EmailKeys.Aggregate(emailTemplate, (current, key) => StringHelper.TemplateParser(current, EmailConstants.EmailKeyRegEx.Replace(EmailConstants.EmailTokenName, key.Key.ToString()), key.Value))); }
public void SendEmailToUser(EmailUser user, EmailTypeOption emailTypes) { var projectRootPath = AppContext.BaseDirectory.Substring(0, AppContext.BaseDirectory.IndexOf("bin", StringComparison.Ordinal)); var templateFolderPath = Path.Combine(projectRootPath, _applicationSettings.EmailTemplatePath); var templateFilePath = Path.Combine(templateFolderPath, emailTypes + ".html"); var templateText = FileHelper.ReadAllLines(templateFilePath); var from = new EmailAddress { DisplayName = _applicationSettings.SmtpSenderName, Address = _applicationSettings.SmtpSenderMail }; string eMailSubject; var emailRow = new EmailRow(); var emailKeys = new List <EmailKey> { new EmailKey { Key = EmailKeyOption.ApplicationName, Value = _applicationSettings.ApplicationName }, new EmailKey { Key = EmailKeyOption.ApplicationUrl, Value = _applicationSettings.ApplicationUrl }, new EmailKey { Key = EmailKeyOption.FirstName, Value = user.FirstName } , new EmailKey { Key = EmailKeyOption.LastName, Value = user.LastName } }; switch (emailTypes) { case EmailTypeOption.Add: { eMailSubject = Dictionary.UserInformation; emailKeys.Add(new EmailKey { Key = EmailKeyOption.Username, Value = user.Username }); emailKeys.Add(new EmailKey { Key = EmailKeyOption.Password, Value = user.Password }); break; } case EmailTypeOption.Register: { eMailSubject = Dictionary.UserInformation; emailKeys.Add(new EmailKey { Key = EmailKeyOption.Username, Value = user.Username }); emailKeys.Add(new EmailKey { Key = EmailKeyOption.Password, Value = user.Password }); emailKeys.Add(new EmailKey { Key = EmailKeyOption.ActivationCode, Value = (user.Id + "@" + user.CreationTime).Encrypt() }); break; } case EmailTypeOption.ForgotPassword: { eMailSubject = Dictionary.NewPassword; emailKeys.Add(new EmailKey { Key = EmailKeyOption.Username, Value = user.Username }); emailKeys.Add(new EmailKey { Key = EmailKeyOption.Password, Value = user.Password }); break; } case EmailTypeOption.Update: { eMailSubject = Dictionary.UserInformation; break; } case EmailTypeOption.UpdateMyPassword: { eMailSubject = Dictionary.NewPassword; emailKeys.Add(new EmailKey { Key = EmailKeyOption.Username, Value = user.Username }); emailKeys.Add(new EmailKey { Key = EmailKeyOption.Password, Value = user.Password }); break; } case EmailTypeOption.UpdateMyInformation: { eMailSubject = Dictionary.UserInformation; break; } default: { throw new ArgumentOutOfRangeException(nameof(emailTypes), emailTypes, null); } } emailKeys.Add(new EmailKey { Key = EmailKeyOption.Subject, Value = eMailSubject }); emailRow.EmailKeys = emailKeys; var eMailMessage = new EmailMessage { To = new List <EmailAddress> { new EmailAddress { Address = user.Email } }, Subject = eMailSubject, From = from, IsBodyHtml = true, Priority = EmailPriorityOption.Normal, Body = ConvertTemplateToString(templateText, emailRow) }; _smtp.Send(eMailMessage); }
private bool updateUser(string associateId, string firstname, string lastname, string fullname, string username, string email, string role, string group, string license, DataGridViewRow item) { bool result = false; try { SoUser user = SoUser.ManageUser(Convert.ToInt32(associateId)); SuperOffice.CRM.Entities.Person p = user.Person; p.Firstname = firstname; p.Lastname = lastname; //p.PersonNumber = username; String pwd = username; EmailRow em = null; if (p.Emails.Count == 0) { em = p.Emails.AddNew(); em.SetDefaults(); } else { em = p.Emails[0]; } // always set correct email; we have just the one address em.EmailAddress = email; em.Protocol = "SMTP"; // save complete person entity p.Save(); //Console.WriteLine("\tPerson/email done"); // set our various properties user.SetPassword(pwd); user.GroupIdx = _groups[group]; user.OtherGroupIds = new int[0]; user.RoleIdx = _roles[role]; user.LogonName = username; user.Tooltip = fullname + " (" + SoSystemInfo.GetCurrent().CompanyName + ")"; // add licenses if (user.GetModuleLicense("SuperOffice", DefaultLicense).CanAssign) { user.GetModuleLicense("SuperOffice", DefaultLicense).Assigned = true; item.Cells["AssignedLicenses"].Value = "Assigned Default"; } else { item.Cells["AssignedLicenses"].Value = "Cannot Assign"; } //user.GetModuleLicense(SoLicenseNames.SuperLicenseServicePro).Assigned = true; /*user.GetModuleLicense(SoLicenseNames.User).Assigned = true; * user.GetModuleLicense(SoLicenseNames.Web).Assigned = true;*/ user.GetModuleLicense(SoLicenseNames.VisibleFor).Assigned = true; // save the user user.Save(); //Console.WriteLine("\tUser saved\n"); result = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } return(result); }
private bool createUser(string firstname, string lastname, string fullname, string username, string email, string role, string group, string company, string license, DataGridViewRow item) { bool result = false; try { // find person by firstname, lastname & owner contact SuperOffice.CRM.Entities.Person.CustomSearch pc = new SuperOffice.CRM.Entities.Person.CustomSearch(); pc.Restriction = pc.TableInfo.Firstname.Equal(S.Parameter(firstname)). And(pc.TableInfo.Lastname.Equal(S.Parameter(lastname))). And(pc.TableInfo.ContactId.Equal(S.Parameter(_contacts[company]))); SuperOffice.CRM.Entities.Person p = SuperOffice.CRM.Entities.Person.GetFromCustomSearch(pc); // we either found an existing person, or got a blank, ready-to-populate one if (p.IsNew) { p.SetDefaults(_contacts[company]); p.Firstname = firstname; p.Lastname = lastname; } // always set userid into number field, for convenience p.PersonNumber = username; // find existing email, or create a new one EmailRow em = null; if (p.Emails.Count == 0) { em = p.Emails.AddNew(); em.SetDefaults(); } else { em = p.Emails[0]; } // always set correct email; we have just the one address em.EmailAddress = email; em.Protocol = "SMTP"; // save complete person entity p.Save(); // if person is associate - get him/her; otherwise create a new SoUser SoUser user; if (AssociateCache.GetCurrent().IsPersonAssociate(p.PersonId)) { user = SoUser.ManageUserFromPersonId(p.PersonId)[0]; } else { user = SoUser.CreateNew(p.PersonId, UserType.InternalAssociate); } // set our various properties user.SetPassword(username); user.GroupIdx = _groups[group]; user.OtherGroupIds = new int[0]; user.RoleIdx = _roles[role]; user.LogonName = username; user.Tooltip = fullname + " (" + company + ")"; // add licenses if (user.GetModuleLicense("SuperOffice", DefaultLicense).CanAssign) { user.GetModuleLicense("SuperOffice", DefaultLicense).Assigned = true; item.Cells["AssignedLicenses"].Value = "Assigned Default"; } else { item.Cells["AssignedLicenses"].Value = "Cannot Assign"; } //user.GetModuleLicense(SoLicenseNames.SuperLicenseServicePro).Assigned = true; /*user.GetModuleLicense(SoLicenseNames.User).Assigned = true; * user.GetModuleLicense(SoLicenseNames.Web).Assigned = true;*/ user.GetModuleLicense(SoLicenseNames.VisibleFor).Assigned = true; // save the user user.Save(); result = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } return(result); }
public EmailRowChangeEvent(EmailRow row, global::System.Data.DataRowAction action) { this.eventRow = row; this.eventAction = action; }