private string GetGroup(MassEmailSendArgs args) { string result = string.Empty; switch (args.Group) { case "community": result = string.Join(", ", CommunityUtility.GetCommunityNames(Combine(args.Values))); break; case "manager": result = Client.GetClient(args.Values.First()).DisplayName; break; case "tools": result = string.Join(", ", Resource.GetResources(args.Values).Select(x => x.ResourceName)); break; case "lab": result = string.Join(", ", Room.GetPassbackRooms().Where(x => args.Values.Contains(x.AreaID)).Select(x => x.AreaName)); break; default: //privilege result = string.Join(", ", PrivUtility.GetPrivTypes((ClientPrivilege)Combine(args.Values))); break; } return(result); }
public int SendMassEmail(MassEmailSendArgs args) { var sma = MassEmail.CreateSendMessageArgs(args); SendMessage(sma); Attachment.Delete(args.Attachments); var result = sma.GetDistinctEmails().Length; return(result); }
public void CanCreateSendMessageArgs() { var args = new MassEmailSendArgs { ClientID = 1301, Caller = "OnlineServices.Api.Tests.MassEmailRepositoryTests.CreateSendMessageArgs", Subject = "Test Email", Body = "Test email.", From = "*****@*****.**", DisplayName = "Getty, James", Group = "privilege", Values = new[] { Convert.ToInt32(ClientPrivilege.Staff) } }; var sma = Provider.Mail.MassEmail.CreateSendMessageArgs(args); Assert.AreEqual(ActiveStaffCount, sma.To.Count()); }
public SendMessageArgs CreateSendMessageArgs(MassEmailSendArgs args) { //var files = new FileCollection("attachments", attachments); return(Post <SendMessageArgs>("webapi/mail/mass-email/send-message-args", args)); }
public int SendMassEmail([FromBody] MassEmailSendArgs args) { return(Provider.Mail.SendMassEmail(args)); }
public SendMessageArgs CreateSendMessageArgs(MassEmailSendArgs args) { if (string.IsNullOrEmpty(args.Group)) { throw new Exception("Group must not be null or empty."); } if (args.Values == null || args.Values.Count() == 0) { throw new Exception("Values must not be null or empty."); } if (string.IsNullOrEmpty(args.Caller)) { throw new Exception("Caller is required."); } if (string.IsNullOrEmpty(args.From)) { throw new Exception("From address is required."); } if (string.IsNullOrEmpty(args.DisplayName)) { throw new Exception("Display name is required."); } if (string.IsNullOrEmpty(args.Subject)) { throw new Exception("Subject is required."); } if (string.IsNullOrEmpty(args.Body)) { throw new Exception("Body is required."); } // an array of file paths var attachments = GetAttachments(args.Attachments); var gs = GlobalSettings.Current; string footer = "\n\n--------------------------------------------------\nThis email has been sent to the following group(s) : " + GetGroup(args) + "."; footer += $"\nYou are receiving this email message because you are associated with the {gs.CompanyName}.\nTo unsubscribe, please go to:\nhttp://ssel-sched.eecs.umich.edu/sselonline/Unsubscribe.aspx"; SendMessageArgs sma = new SendMessageArgs { ClientID = args.ClientID, Caller = args.Caller, Subject = args.Subject, Body = args.Body + footer, From = args.From, DisplayName = args.DisplayName, Attachments = attachments, IsHtml = false }; var recipients = new List <MassEmailRecipient>(); var mgr = new GroupEmailManager(Session); switch (args.Group) { case Groups.Privilege: recipients.AddRange(mgr.GetEmailListByPrivilege(Combine(args.Values))); break; case Groups.Community: recipients.AddRange(mgr.GetEmailListByCommunity(Combine(args.Values))); break; case Groups.Manager: recipients.AddRange(mgr.GetEmailListByManagerID(args.Values.First())); break; case Groups.Tools: recipients.AddRange(mgr.GetEmailListByTools(args.Values.ToArray())); break; case Groups.InLab: recipients.AddRange(mgr.GetEmailListByInLab(args.Values.ToArray())); break; default: throw new NotImplementedException($"Unknown group: {args.Group}"); } if (recipients.Count > 0) { var to = new List <string>(); var cc = new List <string>(); var bcc = new List <string>(); int staffCount = 0; int totalCount = 0; foreach (var recip in recipients) { if (recip.IsStaff) { // we have to expose staff member's emails, so adding to To (not Bcc) AddRecipient(to, recip.Email); staffCount++; } else { AddRecipient(bcc, recip.Email); } totalCount++; } if (!string.IsNullOrEmpty(args.CC)) { AddRecipients(cc, args.CC.Split(',')); } IClient client = Client.GetClient(args.ClientID); bool isStaff = client.HasPriv(ClientPrivilege.Staff); bool recipientsIncludeNonStaff = staffCount != totalCount; if (isStaff && recipientsIncludeNonStaff) { // messages only sent here if staff is sending email to non-staff AddRecipient(bcc, "*****@*****.**"); } // all messages are sent here AddRecipient(bcc, "*****@*****.**"); // apparently we always send to the from address also AddRecipient(to, args.From); sma.To = to.Count == 0 ? null : to; sma.Bcc = bcc.Count == 0 ? null : bcc; sma.Cc = cc.Count == 0 ? null : cc; } return(sma); }
public SendMessageArgs CreateSendMessageArgs([FromBody] MassEmailSendArgs args) { var sma = Provider.Mail.MassEmail.CreateSendMessageArgs(args); return(sma); }
public ActionResult Index(HomeModel model) { InitModel(model, model.SelectedTab); ViewBag.SelectedTab = model.SelectedTab; ViewBag.Message = string.Empty; var group = model.SelectedTab; if (string.IsNullOrEmpty(group)) { throw new Exception("Cannot determine recipient group."); } var values = JsonConvert.DeserializeObject <IEnumerable <int> >(model.SelectedValues); _errors = new List <string>(); if (values.Count() == 0) { _errors.Add("You have not selected any recipients."); } if (string.IsNullOrEmpty(model.From)) { _errors.Add("From address is required."); } if (string.IsNullOrEmpty(model.DisplayName)) { _errors.Add("Display name is required."); } if (string.IsNullOrEmpty(model.Subject)) { _errors.Add("Subject is required."); } if (string.IsNullOrEmpty(model.Body)) { _errors.Add("Body is required."); } if (_errors.Count == 0) { var args = new MassEmailSendArgs { ClientID = CurrentUser.ClientID, Caller = "MassEmail.Controllers.HomeController.Index", Group = group, Values = values, From = model.From, CC = model.CC, DisplayName = model.DisplayName, Subject = model.Subject, Body = model.Body }; if (GetAttachments()) { if (_attachments.Count > 0) { var guid = Provider.Mail.Attachment.Attach(_attachments); args.Attachments = guid; } var sent = Provider.Mail.MassEmail.Send(args); ViewBag.Message = $"Mail sent OK! Emails sent: {sent}"; } } ViewBag.Errors = _errors ?? new List <string>(); // empty list if there were no errors return(View(model)); }
public int SendMassEmail(MassEmailSendArgs args) { return(Post <int>("webapi/mail/send/mass-email", args)); }