public ActionResult AdminEmail(String CompanyURL, AdminSetting Model) { PopulateModel(Model); if (!ModelState.IsValid) { return(View(Model)); } var Email = Context.Emails.Where(e => e.CompanyId == Model.CompanyId && e.EmailName == Model.Key).FirstOrDefault(); if (Email == null) { Email = new Data.Email(); Email.CompanyId = Model.CompanyId; Email.EmailName = Model.Caption; Email.EmailText = Model.Value; Context.Entry(Email).State = System.Data.Entity.EntityState.Added; } else { Email.EmailText = Model.Value; Context.Entry(Email).State = System.Data.Entity.EntityState.Modified; } Context.SaveChanges(); return(View(Model)); }
public Task UpdateAsync(Core.Email email) { String serialized = JsonConvert.SerializeObject(email.Tags); var dto = new Data.Email(email.Id, email.Date, email.Sender.ToLower(), email.Recipient.ToLower(), email.Subject, email.Text, serialized); return(_emailData.UpdateAsync(dto, email.Tags)); }
private async Task SendConfirmationEmail(Data.Registration user, Data.Email email) { string url = Url.Action(nameof(Validate), "Register", new { id = user.Id, secret = user.ConfirmationSecret }); string link = Environment.GetEnvironmentVariable("BASE_URL") + url; Logger.LogTrace(LoggingEvents.Email, "Destination URL {0}, final link {1}", url, link); using (var client = new SmtpClient()) { var credentials = new NetworkCredential( Environment.GetEnvironmentVariable("SMTP_USERNAME"), Environment.GetEnvironmentVariable("SMTP_PASSWORD") ); client.EnableSsl = true; client.Host = Environment.GetEnvironmentVariable("SMTP_HOST"); client.Port = Convert.ToInt32(Environment.GetEnvironmentVariable("SMTP_PORT")); client.Credentials = credentials; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.Timeout = 5000; Logger.LogTrace(LoggingEvents.Email, "SMTP host {0}:{1} username {2} SSL {3}", client.Host, client.Port, credentials.UserName, client.EnableSsl); var noReplyAddress = new MailAddress(Environment.GetEnvironmentVariable("MAIL_FROM"), "CodeMOOC.net"); var msg = new MailMessage { From = noReplyAddress, Subject = "Verifica indirizzo e-mail", IsBodyHtml = false, Body = $"Ciao {user.Name} {user.Surname}!\n\nGrazie per esserti registrato/a su CodeMOOC.net. Ti preghiamo di verificare il tuo indirizzo e-mail cliccando sul seguente link:\n{link}\n\nA presto!\nCodeMOOC.net" }; msg.To.Add(new MailAddress(email.Address, $"{user.Name} {user.Surname}")); if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("CONFIRMATION_MAIL_BCC"))) { msg.Bcc.Add(Environment.GetEnvironmentVariable("CONFIRMATION_MAIL_BCC")); } msg.ReplyToList.Add(noReplyAddress); Logger.LogTrace(LoggingEvents.Email, "Sending e-mail"); try { await client.SendMailAsync(msg); } catch (Exception ex) { Logger.LogError(LoggingEvents.Email, ex, "Failed to send e-mail"); } Logger.LogDebug(LoggingEvents.Email, "E-mail sent"); } }
public void SendEmail(Data.Email email) { using (var message = new MailMessage(new MailAddress(Data.Settings.Instance.EmailFrom, "FCR Service"), new MailAddress(Data.Settings.Instance.EmailTo, "FCR Report Center")) { Subject = email.EmailSubject, Body = email.EmailBody, Priority = MailPriority.High }) { if (email.EmailAttachment != null) { message.Attachments.Add(email.EmailAttachment); } _smtp.Send(message); } }
public static List <Data.Email> getGMailEmail(string inboxPath, string username, string password) { List <Data.Email> emails = new List <Data.Email>(); Data.Email email = null; bool isHtml = true; ImapX.ImapClient client = new ImapX.ImapClient("imap.gmail.com", 993, true); bool result = false; result = client.Connection(); result = client.LogIn(username, password); if (result) { ImapX.FolderCollection folders = client.Folders; ImapX.MessageCollection messages = client.Folders["export"].Search("ALL", true); // .Search("export", true); //true - means all message parts will be received from server if (messages != null && messages.Count > 0) { for (int i = 0; i < messages.Count; i++) { email = new Data.Email(); email.From = messages[i].From.DisplayName; email.Subject = messages[i].Subject; email.TextBody = messages[i].GetDecodedBody(out isHtml); //email.TextBody = messages[i].TextBody.TextData; email.ReceivedDate = messages[i].Date; emails.Add(email); } } } return(emails); }
public static void CreateAndSendFCREmail(string message, Enumerations.EStatus.EmailSubjectStatus subjectStatus) { try { Data.Email email = new Data.Email { EmailSubject = $"{subjectStatus.ToString()} : {++Data.Settings.Instance.Counter}", EmailBody = $"Crash time: {DateTime.Now}{Environment.NewLine}" + $"Machine: {Data.Settings.Instance.MachineName}{Environment.NewLine}" + $"User: {Data.Settings.Instance.UserName}{Environment.NewLine}" + $"Message: {Environment.NewLine} {message}" }; using (EmailProcess oEmailProcess = new EmailProcess()) { oEmailProcess.SendEmail(email); } } catch (Exception ex) { CreateServiceCrashReportJSON($"Original message:{Environment.NewLine}{message}{Environment.NewLine}Send email failed:{Environment.NewLine}{ex.StackTrace}"); } }
public static List<Data.Email> getGMailEmail(string inboxPath, string username, string password) { List<Data.Email> emails = new List<Data.Email>(); Data.Email email = null; bool isHtml = true; ImapX.ImapClient client = new ImapX.ImapClient("imap.gmail.com", 993, true); bool result = false; result = client.Connection(); result = client.LogIn(username, password); if (result) { ImapX.FolderCollection folders = client.Folders; ImapX.MessageCollection messages = client.Folders["export"].Search("ALL", true); // .Search("export", true); //true - means all message parts will be received from server if (messages != null && messages.Count > 0) { for (int i = 0; i < messages.Count; i++) { email = new Data.Email(); email.From = messages[i].From.DisplayName; email.Subject = messages[i].Subject; email.TextBody = messages[i].GetDecodedBody(out isHtml); //email.TextBody = messages[i].TextBody.TextData; email.ReceivedDate = messages[i].Date; emails.Add(email); } } } return emails; }
private static Core.Email ConvertToCoreEmail(Data.Email dto) { var tags = JsonConvert.DeserializeObject <List <String> >(dto.Tags); return(new Core.Email(dto.Id, dto.Date, dto.Sender, dto.Recipient, dto.Subject, dto.Text, tags)); }
public async Task <IActionResult> Process(RegistrationViewModel model, [FromForm(Name = "g-recaptcha-response")] string recaptchaResponse) { Logger.LogInformation(LoggingEvents.Registration, "Received registration request"); // Check e-mail if (!string.IsNullOrWhiteSpace(model.Email)) { var existingMailUser = (from e in Database.Emails where e.Address == model.Email.ToLowerInvariant() select e).SingleOrDefault(); if (existingMailUser != null) { Logger.LogInformation(LoggingEvents.Registration, "E-mail already registered"); ModelState.AddModelError(nameof(RegistrationViewModel.Email), "Indirizzo e-mail già registrato"); } } // Check fiscal code if (!string.IsNullOrWhiteSpace(model.FiscalCode)) { var existingCodeUser = (from r in Database.Registrations where r.FiscalCode == model.FiscalCode.ToUpperInvariant() where r.ConfirmationTimestamp != null select r).SingleOrDefault(); if (existingCodeUser != null) { Logger.LogInformation(LoggingEvents.Registration, "Fiscal code already registered"); ModelState.AddModelError(nameof(RegistrationViewModel.FiscalCode), "Codice fiscale già registrato"); } } // Check birthday if (!DateTime.TryParseExact(model.Birthday, "dd-MM-yyyy", new CultureInfo("it-IT"), DateTimeStyles.AssumeLocal, out var birthday)) { Logger.LogInformation(LoggingEvents.Registration, "Birthday {0} not valid", model.Birthday); ModelState.AddModelError(nameof(RegistrationViewModel.Birthday), "Inserire data di nascita nel formato GG-MM-AAAA"); } // Check ReCaptcha Logger.LogTrace(LoggingEvents.Registration, "Checking ReCaptcha token"); var rest = new RestClient("https://www.google.com/recaptcha/api/siteverify"); var restReq = new RestRequest(Method.POST); restReq.AddParameter("response", recaptchaResponse); restReq.AddParameter("secret", Environment.GetEnvironmentVariable("GOOGLE_RECAPTCHA_SECRET")); var recaptchaResult = rest.Execute <ReCaptchaResponse>(restReq); if (!recaptchaResult.IsSuccessful || !recaptchaResult.Data.Success) { Logger.LogInformation(LoggingEvents.Registration, "ReCaptcha verification failed"); ModelState.AddModelError("ReCaptcha", "Attiva il controllo anti-spam ReCaptcha"); return(View("Create", model)); } Logger.LogDebug(LoggingEvents.Registration, "ReCaptcha verification succeeded for hostname {0}", recaptchaResult.Data.Hostname); // Final validity check if (!ModelState.IsValid) { Logger.LogDebug(LoggingEvents.Registration, "Model binding failed"); return(View("Create", model)); } Logger.LogDebug("Input validated, proceeding with registration"); var hashedPassword = BCrypt.Net.BCrypt.EnhancedHashPassword(model.Password); var user = new Data.Registration { Name = model.Name.Trim(), Surname = model.Surname.Trim(), Birthday = birthday.Date, Birthplace = model.Birthplace, FiscalCode = model.FiscalCode.ToUpperInvariant(), AddressStreet = model.AddressStreet, AddressCity = model.AddressCity, AddressCap = model.AddressCap, AddressCountry = model.AddressCountry, PasswordSchema = "bcrypt.net", // hard-coded to hash function PasswordHash = hashedPassword, Category = model.Category, HasAttendedMooc = model.HasAttendedMooc, HasCompletedMooc = model.HasCompletedMooc, RegistrationTimestamp = DateTime.UtcNow, ConfirmationSecret = Startup.GenerateSecret() }; Database.Registrations.Add(user); var email = new Data.Email { Address = model.Email.Trim().ToLowerInvariant(), IsPrimary = true, AssociationTimestamp = user.RegistrationTimestamp, Registration = user }; Database.Emails.Add(email); int changes = Database.SaveChanges(); if (changes != 2) { throw new InvalidOperationException("Expected changes equal to 2 when registering user"); } await SendConfirmationEmail(user, email); // Confirmation view ViewData["email"] = email.Address; return(View("Confirm")); }