private async Task <TimeSpan> SendNotifications(ServiceStatusResult statusResult) { List <Task> tasks = new List <Task>(); List <TimeSpan> gracePeriods = new List <TimeSpan>(); // Send service up notifications List <SubscriptionResults> serviceUpMailRecepients = await GetSubscribers(statusResult.WentOnline); foreach (SubscriptionResults recepient in serviceUpMailRecepients) { // TODO: Read text from config file tasks.Add(mailingService.Send(recepient.User.Email, "Service Up", GetMessageBody(recepient.Subscriptions.Select(s => s.Service).ToList()))); } // Send service down notifications List <SubscriptionResults> serviceDownMailRecepients = await GetSubscribers(statusResult.WentOffline); foreach (SubscriptionResults recepient in serviceDownMailRecepients) { // TODO: Read text from config file tasks.Add(mailingService.Send(recepient.User.Email, "Service Down", GetMessageBody(recepient.Subscriptions.Select(s => s.Service).ToList()))); gracePeriods.AddRange(recepient.Subscriptions.Select(s => s.GracePeriod)); } await Task.WhenAll(tasks.ToArray()); // Find the minimum grace period out of all subscriptions (excluding zeros) // If no entries found return a big value, so it will be ignored and polling freaquency will be considered var minimumGracePeriod = gracePeriods.Count > 0 ? gracePeriods.Min() : new TimeSpan(24, 0, 0); return(minimumGracePeriod); }
public void SendMail(string title, string message, string mailAddress) { _service.Send(new Message() { Title = title, Body = message, Receiver = mailAddress }); }
public async Task <Invitation> SendInvitation(Guid invitationId, string to, Func <string, string> getSignupUrl) { // Note: creating a user with the invitation e-mail first makes sure that the user ever only receives // one invitation as the Identity will refuse to create two users with the same e-mail. var user = new ApplicationUser { UserName = invitationId.ToString(), Email = to, }; Assert(await _userManager.CreateAsync(user)); // send invitiation e-mail string code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var url = getSignupUrl(code); string error = await _mailing.Send(to, "Join the esme Community", $"Follow this link: {url} to join the community. This invitation expires in {Constants.JoinInvitationExpirationDays} days."); // FIXME: da, can we set the sender to invitor's e-mail? return(new Invitation { Id = invitationId, To = to, SentAt = DateTimeOffset.UtcNow, Error = error, }); }
public IActionResult DeletePointofInterest(int cityId, int id) { // var city = CitiesDataStore.Current.Cities.FirstOrDefault(c => c.ID == cityId); if (!_cityInfoRepository.IfCityExists(cityId)) { return(BadRequest()); } var pointOfInterestFromEntity = _cityInfoRepository.GetPointofInterest(cityId, id); if (pointOfInterestFromEntity == null) { return(BadRequest()); } _cityInfoRepository.DeletePointofInterest(pointOfInterestFromEntity); if (!_cityInfoRepository.Save()) { return(StatusCode(500, "Internal Server Error")); } _mailingService.Send(pointOfInterestFromEntity.Name, "is Deleted"); return(NoContent()); }
private async Task SendReportMailWithHeaderImageAsync(IEnumerable <NinjaDTO> data, string emailAddress) { var headerImagePath = string.Format("{0}/{1}", _environment.WebRootPath, "images/mail-header-solid.png"); var mailingModel = new MailContentDTO(); mailingModel.HeaderImage = new LinkedResource { ContentId = "header", ContentPath = headerImagePath, ContentType = "image/png" }; mailingModel.HtmlContent = await GetGridContentAsync(data); _mailingService.Send(emailAddress, "Your Report", mailingModel); }
private async Task SendHistory() { if (IsBusy) { return; } IsBusy = true; await Task.Run(() => { try { var exported = _exportService.Export(_dataService); _mailingService.Send(Email, _mailTitle, exported); } finally { IsBusy = false; } }); }