public Boolean SendMail(string from, List <string> emailList, string subject, string bodyHtml, TForm newForm, Int32 formId, SystemUsers sentUser) { try { MailMessage completeMessage = new MailMessage(); completeMessage.From = new MailAddress(from); completeMessage.Subject = subject; completeMessage.Body = bodyHtml; completeMessage.IsBodyHtml = true; //SmtpClient client = new SmtpClient("TingleNT30.wctingle.com"); //client.UseDefaultCredentials = true; SmtpClient client = new SmtpClient("smtp.gmail.com", 587); client.Credentials = new NetworkCredential("*****@*****.**", "ZXCasdQWE123!"); client.EnableSsl = true; using (FormContext ctx = new FormContext()) { foreach (string email in emailList) { RequestNotifications newRN = new RequestNotifications { Form = ctx.TForms.FirstOrDefault(x => x.FormID == newForm.FormID), BodyHtml = bodyHtml, RequestedFormId = formId, SentBy = ctx.SystemUsers.FirstOrDefault(x => x.SystemUserID == sentUser.SystemUserID), Status = 0, Timestamp = DateTime.Now, ToEmailAddress = email }; ctx.RequestNotifications.Add(newRN); ctx.SaveChanges(); try { completeMessage.To.Clear(); completeMessage.To.Add(email); client.Send(completeMessage); newRN.Status = 1; ctx.SaveChanges(); } catch (Exception exc) {} } } return(true); } catch (Exception ex) { return(false); //throw ex; } }
private void AddRequestNotifications(int requestId) { try { var request = NiisAmbientContext.Current.Executor.GetQuery <GetRequestByIdQuery>().Process(q => q.Execute(requestId)); if (request == null) { throw new Exception($"Notification register error: request with id {requestId} not found!"); } var notificationTaskQueues = new RequestNotifications().GenerateNotificationTaskQueue(request); NiisAmbientContext.Current.Executor.GetCommand <CreateNotificationTaskQueuesCommand>().Process(c => c.Execute(notificationTaskQueues)); } catch (Exception e) { Log.Error(e, "Sms notification send error: " + e.Message); } }