/// <summary> /// Emails from from master. /// </summary> /// <param name = "variables">The variables lust of string to be replace ie Nate Priddy with {!from}.</param> /// <param name = "subject">The subject.</param> /// <param name = "to">To.</param> /// <param name = "cc">The cc.</param> /// <datetime>6/17/2011-10:16 AM</datetime> /// <author> /// nate /// </author> public static void EmailFromFromMaster(IEnumerable <KeyValuePair <string, string> > variables, string subject, User to, IEnumerable <int> cc) { var html = GetHtmlTemplate(); var text = ""; EmailUtilities.Replacer(variables, ref html, ref text, ref subject); EmailUtilities.SendEmail(html, text, subject, to.FirstName + " " + to.LastName, to.Email, cc); }
public int RegisterPerson(Person p) { int result = da.AddPerson(p); if (result == 1) { EmailUtilities.SendEmail(ConfigurationManager.AppSettings["EmailUsername"], p.Email, "Registration to Speakcore Conference", $"<p>Dear {p.FirstName},</p><p></p>" + "<p>On behalf of Pharma Company, Inc., thank you for registering for the Speaker Training Meeting.</p><p></p>" + "<p>You will receive a formal confirmatiomn email within the next 3 to 5 business days, including " + "information for booking your travel.</p><p></p>" + "<p>Regards,</p><p>The SpeakCore Team</p>"); } return(result); // What if registration succeeded and email send failed? }
protected void ResetButton_Click(object sender, EventArgs e) { if (!Page.IsValid) { return; } string emailAddress = EmailTextBox.Text; string userName = Membership.GetUserNameByEmail(emailAddress); if (String.IsNullOrEmpty(userName)) { // This should not have happened. //log.Error("Failed to find the specified email address in our system: " + emailAddress); ErrorLabel.Text = Resources.LoginGlossary.MensajeUsuarioNoEncontrado; ErrorLabel.ForeColor = System.Drawing.Color.Red; return; } string newPass = ""; try { MembershipUser user = Membership.GetUser(userName, false); if (user == null) { ErrorLabel.Text = Resources.LoginGlossary.MensajeUsuarioNoEncontrado; ErrorLabel.ForeColor = System.Drawing.Color.Red; return; } user.IsApproved = true; newPass = user.ResetPassword(); if (string.IsNullOrEmpty(newPass)) { log.Error("No se genero la nueva contraseña."); ErrorLabel.Text = Resources.LoginGlossary.MensajeErrorContraseñaVacia; ErrorLabel.ForeColor = System.Drawing.Color.Red; return; } Membership.UpdateUser(user); } catch { ErrorLabel.Text = "No se pudo cambiar la constraseña del usuario. Comuníquese con el Administrador del Sistema."; ErrorLabel.ForeColor = System.Drawing.Color.Red; return; } StringBuilder mailText = new StringBuilder(); try { // Ok. Get the template for the email string emailFile = HttpContext.Current.Server.MapPath(Resources.Files.NewPasswordFileLocation); using (System.IO.StreamReader sr = System.IO.File.OpenText(emailFile)) { string s = ""; while ((s = sr.ReadLine()) != null) { mailText.Append(s); } } } catch { ErrorLabel.Text = Resources.LoginGlossary.MensajeNoEnvioMail; ErrorLabel.ForeColor = System.Drawing.Color.Red; return; } mailText.Replace("{UserName}", userName); mailText.Replace("{Password}", newPass); try { EmailUtilities.SendEmail(emailAddress, Configuration.GetConfirmationPasswordSubject(), mailText.ToString()); } catch (Exception q) { //log.Error("Failed to send email with validation code for user " + userName, q); ErrorLabel.Text = Resources.LoginGlossary.MensajeNoEnvioMail + ": " + q.Message;; ErrorLabel.ForeColor = System.Drawing.Color.Red; return; } ErrorLabel.Text = Resources.LoginGlossary.MensajeEnvioMail; ErrorLabel.ForeColor = System.Drawing.Color.Black; Response.Redirect("~/Authentication/ConfirmarReseteo.aspx"); }
private void SendNotificationsConcerso() { try { string nombre = ""; string email = ""; string mensaje = ""; if (!string.IsNullOrEmpty(nombretxt.Text)) { nombre = nombretxt.Text; } else { errorNombre.Visible = true; return; } if (!string.IsNullOrEmpty(Emailtxt.Text)) { email = Emailtxt.Text; } else { errorEmail.Visible = true; return; } if (!string.IsNullOrEmpty(mensajeTxt.Text)) { mensaje = mensajeTxt.Text; } else { errorMensaje.Visible = true; return; } string text = System.IO.File.ReadAllText(Server.MapPath("~/Email/EnvioEmail.html")); StringBuilder message = new StringBuilder(text); message.Replace("<%Name%>", nombre); message.Replace("<%mensaje%>", mensaje); string root = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath; string link = root + "/Conserso.aspx"; message.Replace("<%Link%>", link); //Notificar al cliente EmailUtilities.SendEmail(email, "Conserso - Consulta cliente", message.ToString()); mensajeTxt.Text = ""; nombretxt.Text = ""; Emailtxt.Text = ""; } catch (Exception ex) { throw ex; //log.Error("Error sending email to client", ex); } }
// Technical Debt: should be named ForgottenMail public override object Execute(Content content, params object[] parameters) { Dictionary <string, string> result = new Dictionary <string, string>(); // Load user if we can string useremail = parameters[0] as string; // Check if caller user is in the proper group and gets target company // User must have been a member of Security Editors of the given company or a system administrator if (!string.IsNullOrWhiteSpace(useremail)) { Content loadedUserContent = null; using (new SystemAccount()) { loadedUserContent = Content.All.DisableAutofilters().Where(u => u.Type("RorWebUser") && (string)u["Email"] == useremail).FirstOrDefault(); if (loadedUserContent != null) { //loadedUserContent["Enabled"] = false; string confirmationGuid = Guid.NewGuid().ToString(); loadedUserContent["PasswordResetGuid"] = confirmationGuid; loadedUserContent["RequestChangePasswDate"] = DateTime.UtcNow; loadedUserContent.Save(); string fromEmail = Settings.GetValue <string>(EmailSettingsName, "EmailNotificationFrom"); var addresses = Settings.GetValue <string[]>(EmailSettingsName, "EmailNotificationTo"); string subject = Settings.GetValue <string>(EmailSettingsName, "EmailChangePassSubject"); // Technical Debt: guid msut be injected to email body string emailTemplatePath = Settings.GetValue <string>(EmailSettingsName, "EmailForgottenBodyTemplatePath"); string emailTemplatePathForAdmin = Settings.GetValue <string>(EmailSettingsName, "EmailForgottenBodyTemplatePathForAdmin"); //emailTemplatePath = "/Root/Skins/rorweb/Templates/EmailTemplates/ConfirmationMail.html"; Node emailTemplateNode = Node.LoadNodeByIdOrPath(emailTemplatePath); Node emailTemplateNodeForAdmin = Node.LoadNodeByIdOrPath(emailTemplatePathForAdmin); string emailTemplate = emailTemplateNode?.GetBinaryToString(); string emailTemplateForAdmin = emailTemplateNodeForAdmin?.GetBinaryToString(); emailTemplate = emailTemplate.Replace("{User.UserName}", loadedUserContent["LoginName"] as string); emailTemplate = emailTemplate.Replace("{User.DisplayName}", loadedUserContent["DisplayName"] as string); emailTemplate = emailTemplate.Replace("{User.ConfirmationGuid}", loadedUserContent["PasswordResetGuid"] as string); emailTemplate = emailTemplate.Replace("{Site.Url}", HttpContext.Current.Request.Url.Host); emailTemplateForAdmin = emailTemplateForAdmin.Replace("{User.UserName}", loadedUserContent["LoginName"] as string); emailTemplateForAdmin = emailTemplateForAdmin.Replace("{User.ConfirmationGuid}", loadedUserContent["PasswordResetGuid"] as string); emailTemplateForAdmin = emailTemplateForAdmin.Replace("{Site.Url}", HttpContext.Current.Request.Url.Host); string toEmail = loadedUserContent["Email"] as string; if (string.IsNullOrWhiteSpace(toEmail)) { toEmail = "*****@*****.**"; subject = subject + " (no email!)"; } Parallel.ForEach(addresses, x => { //bool validUser = SenseNet.ContentRepository.Content.All.DisableAutofilters().DisableLifespan().Any(c => c.TypeIs("User") && (string)c["Email"] == x.UserEmail); //if (validUser) { EmailUtilities.SendEmail( new System.Net.Mail.MailAddress(fromEmail, fromEmail), x, null, subject, emailTemplateForAdmin); } }); EmailUtilities.SendEmail( new System.Net.Mail.MailAddress(fromEmail, fromEmail), toEmail, null, subject, emailTemplate); } else { // usser does not exist, but no problem } } } else { throw new Exception("Valamit elfelejtettel!"); } return(JsonConvert.SerializeObject(result, new KeyValuePairConverter()));; }