private async Task EmailAvailableRequest(NotificationModel model, EmailNotificationSettings settings) { if (!settings.EnableUserEmailNotifications) { await Task.FromResult(false); } var email = new EmailBasicTemplate(); var html = email.LoadTemplate( $"Ombi: {model.Title} is now available!", $"Hello! You requested {model.Title} on PlexRequests! This is now available on Plex! :)", model.ImgSrc); var body = new BodyBuilder { HtmlBody = html, TextBody = $"Hello! You requested {model.Title} on PlexRequests! This is now available on Plex! :)" }; var message = new MimeMessage { Body = body.ToMessageBody(), Subject = $"Ombi: {model.Title} is now available!" }; message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender)); message.To.Add(new MailboxAddress(model.UserEmail, model.UserEmail)); await Send(message, settings); }
protected override async Task Test(NotificationOptions model, EmailNotificationSettings settings) { var email = new EmailBasicTemplate(); var html = email.LoadTemplate( "Test Message", "This is just a test! Success!", "", Customization.Logo); var message = new NotificationMessage { Message = html, Subject = $"Ombi: Test", }; message.Other.Add("PlainTextBody", "This is just a test! Success!"); await SendToAdmins(message, settings); }
protected override async Task Test(NotificationModel model, EmailNotificationSettings settings) { var email = new EmailBasicTemplate(); var html = email.LoadTemplate( "Test Message", "This is just a test! Success!", model.ImgSrc); var message = new NotificationMessage { Message = html, Subject = $"Ombi: Test", To = settings.RecipientEmail, }; message.Other.Add("PlainTextBody", "This is just a test! Success!"); await Send(message, settings); }
protected override async Task RequestApproved(NotificationModel model, EmailNotificationSettings settings) { var email = new EmailBasicTemplate(); var html = email.LoadTemplate( "Ombi: Your request has been approved!", $"Hello! Your request for {model.Title} has been approved!", model.ImgSrc); var message = new NotificationMessage { Message = html, Subject = $"Ombi: Your request has been approved!", To = model.UserEmail, }; message.Other.Add("PlainTextBody", $"Hello! Your request for {model.Title} has been approved!"); await Send(message, settings); }
private async Task <NotificationMessage> LoadTemplate(NotificationType type, NotificationOptions model, EmailNotificationSettings settings) { var parsed = await LoadTemplate(NotificationAgent.Email, type, model); if (parsed.Disabled) { Logger.LogInformation($"Template {type} is disabled for {NotificationAgent.Email}"); return(null); } var email = new EmailBasicTemplate(); var html = email.LoadTemplate(parsed.Subject, parsed.Message, parsed.Image, Customization.Logo); var message = new NotificationMessage { Message = html, Subject = parsed.Subject, }; if (model.Substitutes.TryGetValue("AdminComment", out var isAdminString)) { var isAdmin = bool.Parse(isAdminString); if (isAdmin) { var user = _userManager.Users.FirstOrDefault(x => x.Id == model.UserId); // Send to user message.To = user.Email; } else { // Send to admin message.To = settings.AdminEmail; } } else { // Send to admin message.To = settings.AdminEmail; } return(message); }
protected override async Task NewRequest(NotificationModel model, EmailNotificationSettings settings) { var email = new EmailBasicTemplate(); var html = email.LoadTemplate( $"Ombi: New {model.RequestType.GetString()?.ToLower()} request for {model.Title}!", $"Hello! The user '{model.User}' has requested the {model.RequestType.GetString()?.ToLower()} '{model.Title}'! Please log in to approve this request. Request Date: {model.DateTime.ToString("f")}", model.ImgSrc); var message = new NotificationMessage { Message = html, Subject = $"Ombi: New {model.RequestType.GetString()?.ToLower()} request for {model.Title}!", To = settings.RecipientEmail, }; message.Other.Add("PlainTextBody", $"Hello! The user '{model.User}' has requested the {model.RequestType.GetString()?.ToLower()} '{model.Title}'! Please log in to approve this request. Request Date: {model.DateTime.ToString("f")}"); await Send(message, settings); }
protected override async Task AvailableRequest(NotificationModel model, EmailNotificationSettings settings) { var email = new EmailBasicTemplate(); var html = email.LoadTemplate( $"Ombi: {model.Title} is now available!", $"Hello! You requested {model.Title} on Ombi! This is now available on Plex! :)", model.ImgSrc); var message = new NotificationMessage { Message = html, Subject = $"Ombi: {model.Title} is now available!", To = model.UserEmail, }; message.Other.Add("PlainTextBody", $"Hello! You requested {model.Title} on Ombi! This is now available on Plex! :)"); await Send(message, settings); }
protected override async Task AddedToRequestQueue(NotificationModel model, EmailNotificationSettings settings) { var email = new EmailBasicTemplate(); var html = email.LoadTemplate( "Ombi: A request could not be added.", $"Hello! The user '{model.User}' has requested {model.Title} but it could not be added. This has been added into the requests queue and will keep retrying", model.ImgSrc); var message = new NotificationMessage { Message = html, Subject = $"Ombi: A request could not be added", To = settings.RecipientEmail, }; message.Other.Add("PlainTextBody", $"Hello! The user '{model.User}' has requested {model.Title} but it could not be added. This has been added into the requests queue and will keep retrying"); await Send(message, settings); }
private async Task EmailTest(NotificationModel model, EmailNotificationSettings settings) { var email = new EmailBasicTemplate(); var html = email.LoadTemplate( "Test Message", "This is just a test! Success!", model.ImgSrc); var body = new BodyBuilder { HtmlBody = html, }; var message = new MimeMessage { Body = body.ToMessageBody() }; message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender)); message.To.Add(new MailboxAddress(settings.RecipientEmail, settings.RecipientEmail)); await Send(message, settings); }
protected override async Task Issue(NotificationModel model, EmailNotificationSettings settings) { var email = new EmailBasicTemplate(); var html = email.LoadTemplate( $"Ombi: New issue for {model.Title}!", $"Hello! The user '{model.User}' has reported a new issue {model.Body} for the title {model.Title}!", model.ImgSrc); var message = new NotificationMessage { Message = html, Subject = $"Ombi: New issue for {model.Title}!", To = settings.RecipientEmail, }; message.Other.Add("PlainTextBody", $"Hello! The user '{model.User}' has reported a new issue {model.Body} for the title {model.Title}!"); await Send(message, settings); }
private async Task <NotificationMessage> LoadTemplate(NotificationType type, NotificationOptions model, EmailNotificationSettings settings) { var parsed = await LoadTemplate(NotificationAgent.Email, type, model); if (parsed.Disabled) { Logger.LogInformation($"Template {type} is disabled for {NotificationAgent.Email}"); return(null); } var email = new EmailBasicTemplate(); var html = email.LoadTemplate(parsed.Subject, parsed.Message, parsed.Image, Customization.Logo, parsed.DetailsUrl); var message = new NotificationMessage { Message = html, Subject = parsed.Subject, }; return(message); }
private async Task EmailRequestApproved(NotificationModel model, EmailNotificationSettings settings) { var email = new EmailBasicTemplate(); var html = email.LoadTemplate( "Ombi: Your request has been approved!", $"Hello! Your request for {model.Title} has been approved!", model.ImgSrc); var body = new BodyBuilder { HtmlBody = html, TextBody = $"Hello! Your request for {model.Title} has been approved!", }; var message = new MimeMessage { Body = body.ToMessageBody(), Subject = $"Ombi: Your request has been approved!" }; message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender)); message.To.Add(new MailboxAddress(model.UserEmail, model.UserEmail)); await Send(message, settings); }
private async Task EmailAddedToRequestQueue(NotificationModel model, EmailNotificationSettings settings) { var email = new EmailBasicTemplate(); var html = email.LoadTemplate( "Ombi: A request could not be added.", $"Hello! The user '{model.User}' has requested {model.Title} but it could not be added. This has been added into the requests queue and will keep retrying", model.ImgSrc); var body = new BodyBuilder { HtmlBody = html, TextBody = $"Hello! The user '{model.User}' has requested {model.Title} but it could not be added. This has been added into the requests queue and will keep retrying" }; var message = new MimeMessage { Body = body.ToMessageBody(), Subject = $"Ombi: A request could not be added" }; message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender)); message.To.Add(new MailboxAddress(settings.RecipientEmail, settings.RecipientEmail)); await Send(message, settings); }
private async Task EmailIssue(NotificationModel model, EmailNotificationSettings settings) { var email = new EmailBasicTemplate(); var html = email.LoadTemplate( $"Ombi: New issue for {model.Title}!", $"Hello! The user '{model.User}' has reported a new issue {model.Body} for the title {model.Title}!", model.ImgSrc); var body = new BodyBuilder { HtmlBody = html, TextBody = $"Hello! The user '{model.User}' has reported a new issue {model.Body} for the title {model.Title}!" }; var message = new MimeMessage { Body = body.ToMessageBody(), Subject = $"Ombi: New issue for {model.Title}!" }; message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender)); message.To.Add(new MailboxAddress(settings.RecipientEmail, settings.RecipientEmail)); await Send(message, settings); }
private async Task EmailNewRequest(NotificationModel model, EmailNotificationSettings settings) { var email = new EmailBasicTemplate(); var html = email.LoadTemplate( $"Ombi: New {model.RequestType.GetString()?.ToLower()} request for {model.Title}!", $"Hello! The user '{model.User}' has requested the {model.RequestType.GetString()?.ToLower()} '{model.Title}'! Please log in to approve this request. Request Date: {model.DateTime.ToString("f")}", model.ImgSrc); var body = new BodyBuilder { HtmlBody = html, TextBody = $"Hello! The user '{model.User}' has requested the {model.RequestType.GetString()?.ToLower()} '{model.Title}'! Please log in to approve this request. Request Date: {model.DateTime.ToString("f")}" }; var message = new MimeMessage { Body = body.ToMessageBody(), Subject = $"Ombi: New {model.RequestType.GetString()?.ToLower()} request for {model.Title}!" }; message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender)); message.To.Add(new MailboxAddress(settings.RecipientEmail, settings.RecipientEmail)); await Send(message, settings); }
protected override async Task AddedToRequestQueue(NotificationOptions model, EmailNotificationSettings settings) { var email = new EmailBasicTemplate(); var user = string.Empty; var title = string.Empty; var img = string.Empty; if (model.RequestType == RequestType.Movie) { user = MovieRequest.RequestedUser.UserAlias; title = MovieRequest.Title; img = $"https://image.tmdb.org/t/p/w300/{MovieRequest.PosterPath}"; } else { user = TvRequest.RequestedUser.UserAlias; title = TvRequest.ParentRequest.Title; img = TvRequest.ParentRequest.PosterPath; } var html = email.LoadTemplate( $"{Customization.ApplicationName}: A request could not be added.", $"Hello! The user '{user}' has requested {title} but it could not be added. This has been added into the requests queue and will keep retrying", img, Customization.Logo); var message = new NotificationMessage { Message = html, Subject = $"{Customization.ApplicationName}: A request could not be added", To = settings.AdminEmail, }; var plaintext = $"Hello! The user '{user}' has requested {title} but it could not be added. This has been added into the requests queue and will keep retrying"; message.Other.Add("PlainTextBody", plaintext); await Send(message, settings); }
/// <summary> /// This will load up the Email template and generate the HTML /// </summary> /// <param name="model"></param> /// <param name="settings"></param> /// <returns></returns> public async Task SendAdHoc(NotificationMessage model, EmailNotificationSettings settings) { try { var email = new EmailBasicTemplate(); var customization = await CustomizationSettings.GetSettingsAsync(); var html = email.LoadTemplate(model.Subject, model.Message, null, customization.Logo); var textBody = string.Empty; model.Other.TryGetValue("PlainTextBody", out textBody); var body = new BodyBuilder { HtmlBody = html, TextBody = textBody }; var message = new MimeMessage { Body = body.ToMessageBody(), Subject = model.Subject }; message.From.Add(new MailboxAddress(string.IsNullOrEmpty(settings.SenderName) ? settings.SenderAddress : settings.SenderName, settings.SenderAddress)); message.To.Add(new MailboxAddress(model.To, model.To)); using (var client = new SmtpClient()) { if (settings.DisableCertificateChecking) { // Disable validation of the certificate associated with the SMTP service // Helpful when the TLS certificate is not in the certificate store of the server // Does carry the risk of man in the middle snooping client.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true; } if (settings.DisableTLS) { // Does not attempt to use either TLS or SSL // Helpful when MailKit finds a TLS certificate, but it unable to use it client.Connect(settings.Host, settings.Port, MailKit.Security.SecureSocketOptions.None); } else { client.Connect(settings.Host, settings.Port); // Let MailKit figure out the correct SecureSocketOptions. } // Note: since we don't have an OAuth2 token, disable // the XOAUTH2 authentication mechanism. client.AuthenticationMechanisms.Remove("XOAUTH2"); if (settings.Authentication) { client.Authenticate(settings.Username, settings.Password); } _log.LogDebug("sending message to {0} \r\n from: {1}\r\n Are we authenticated: {2}", message.To, message.From, client.IsAuthenticated); await client.SendAsync(message); await client.DisconnectAsync(true); } } catch (Exception e) { _log.LogError(e, "Exception when attempting to send an email"); throw; } }