public object Post(TestNotification request) { var options = GetOptions(request.UserID); var mail = new MailMessage(options.EmailFrom, options.EmailTo) { Subject = "Media Browser: Test Notification", Body = "This is a test notification from MediaBrowser" }; var client = new SmtpClient { Host = options.Server, Port = options.Port, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false }; if (options.SSL) { client.EnableSsl = true; } if (options.UseCredentials) { var pw = _encryption.DecryptString(options.PwData); client.Credentials = new NetworkCredential(options.Username, pw); } return(client.SendMailAsync(mail)); }
private Task SendNotificationInternal(UserNotification request, CancellationToken cancellationToken) { var options = GetOptions(request.User); var mail = new MailMessage(options.EmailFrom, options.EmailTo) { Subject = "Emby: " + request.Name, Body = request.Description }; var client = new SmtpClient { Host = options.Server, Port = options.Port, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false }; if (options.SSL) { client.EnableSsl = true; } _logger.Debug("Emailing {0} with subject {1}", options.EmailTo, mail.Subject); if (options.UseCredentials) { var pw = _encryption.DecryptString(options.PwData); client.Credentials = new NetworkCredential(options.Username, pw); } return(client.SendMailAsync(mail)); }
private void LoadCachedData() { var path = CacheFilePath; _logger.Info("Loading data from {0}", path); try { lock (_dataFileLock) { var encrypted = _fileSystem.ReadAllText(path, Encoding.UTF8); var json = _encryption.DecryptString(encrypted); _data = _json.DeserializeFromString <ConnectData>(json); } } catch (IOException) { // File isn't there. no biggie } catch (Exception ex) { _logger.ErrorException("Error loading data", ex); } }
private void LoadCachedAddress() { var path = CacheFilePath; _logger.Info("Loading data from {0}", path); try { var endpoint = _encryption.DecryptString(_fileSystem.ReadAllText(path, Encoding.UTF8)); IpAddressInfo ipAddress; if (_networkManager.TryParseIpAddress(endpoint, out ipAddress)) { _cachedIpAddress = ipAddress; ((ConnectManager)_connectManager).OnWanAddressResolved(ipAddress); } } catch (IOException) { // File isn't there. no biggie } catch (Exception ex) { _logger.ErrorException("Error loading data", ex); } }
private string DecryptPassword(string password) { if (password == null || !password.StartsWith(PasswordHashPrefix, StringComparison.OrdinalIgnoreCase)) { return(string.Empty); } return(_encryption.DecryptString(password.Substring(2))); }
public async Task SendNotification(UserNotification request, CancellationToken cancellationToken) { var options = GetOptions(request.User); using (var mail = new MailMessage(options.EmailFrom, options.EmailTo) { Subject = "Emby: " + request.Name, Body = string.Format("{0}\n\n{1}", request.Name, request.Description) }) { using (var client = new SmtpClient { Host = options.Server, Port = options.Port, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Timeout = 20000 }) { if (options.SSL) { client.EnableSsl = true; } _logger.Info("Sending email {0} with subject {1}", options.EmailTo, mail.Subject); if (options.UseCredentials) { var pw = string.IsNullOrWhiteSpace(options.Password) ? _encryption.DecryptString(options.PwData) : options.Password; client.Credentials = new NetworkCredential(options.Username, pw); } try { await client.SendMailAsync(mail).ConfigureAwait(false); _logger.Info("Completed sending email {0} with subject {1}", options.EmailTo, mail.Subject); } catch (Exception ex) { _logger.Error("Error sending email: {0} ", ex); } } } }
public void AttemptLogin(bool createNotificationOnFailure) { var username = Instance.Configuration.Username; var password = _encryption.DecryptString(Instance.Configuration.PwData); if (!string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password)) { try { _soundCloudClient.Authenticate(username, password); } catch (Exception ex) { var msg = "Unable to login to SoundCloud. Please check username and password."; //if (!string.IsNullOrWhiteSpace(ex.ResponseBody)) //{ // msg = string.Format("{0} ({1})", msg, ex.ResponseBody); //} _logger.ErrorException(msg, ex); if (createNotificationOnFailure) { var request = new NotificationRequest { Description = msg, Date = DateTime.Now, Level = NotificationLevel.Error, SendToUserMode = SendToUserType.Admins }; _notificationManager.SendNotification(request, CancellationToken.None); } else { msg = string.Format("{0}\n\nAttention: You need to wait up to 3 minutes before retrying!", msg); throw new Exception(msg); } } } }
private void LoadCachedData() { var path = CacheFilePath; try { var encrypted = File.ReadAllText(path, Encoding.UTF8); var json = _encryption.DecryptString(encrypted); var data = _json.DeserializeFromString <ConnectData>(json); ConnectAccessKey = data.AccessKey; ConnectServerId = data.ServerId; } catch (IOException) { // File isn't there. no biggie } catch (Exception ex) { _logger.ErrorException("Error loading data", ex); } }
public async Task SendNotification(UserNotification request, CancellationToken cancellationToken) { var options = GetOptions(request.User); var mail = new MimeMessage(); var bodyBuilder = new BodyBuilder(); try { mail.From.Add(new MailboxAddress(options.EmailFromName, options.EmailFrom)); mail.To.Add(new MailboxAddress("", options.EmailTo)); } catch (Exception ex) { _logger.Error("Error creating Mailbox Address objects for from:{0} or to:{1} (error: {2})", options.EmailFrom, options.EmailTo, ex.Message); /* If testing SMTP, push exception to API caller */ if (request.Name == "Test Notification") { throw ex; } } mail.Subject = "Emby: " + request.Name; bodyBuilder.HtmlBody = string.Format("{0}<br/><br/>{1}", request.Name, request.Description); bodyBuilder.TextBody = string.Format("{0}\n\n{1}", request.Name, request.Description); mail.Body = bodyBuilder.ToMessageBody(); var client = new MailKit.Net.Smtp.SmtpClient(); if (options.IgnoreCertificateErrors.GetValueOrDefault(false)) { client.ServerCertificateValidationCallback = this.sslCertificateValidationCallback; } client.Timeout = 20000; try { _logger.Info("Connecting to smtpserver at {0}:{1}", options.Server, options.Port); await client.ConnectAsync(options.Server, options.Port, options.SSL).ConfigureAwait(false); if (options.UseCredentials) { _logger.Info("Authenticating to smtpserver using {0}/<hidden>", options.Username); var pw = string.IsNullOrWhiteSpace(options.Password) ? _encryption.DecryptString(options.PwData) : options.Password; try { await client.AuthenticateAsync(new NetworkCredential(options.Username, pw)).ConfigureAwait(false); } catch (Exception ex) { _logger.Info("Failed to authenticate to SMTP server: {0}", ex.Message); /* If testing SMTP, push exception to API caller */ if (request.Name == "Test Notification") { throw ex; } } } _logger.Info("Sending email {0} with subject {1}", options.EmailTo, mail.Subject); await client.SendAsync(mail, default, null).ConfigureAwait(false);
public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer, IEncryptionManager encryption) : base(applicationPaths, xmlSerializer) { Instance = this; _encryption = encryption; var username = Instance.Configuration.Username; var password = Instance.Configuration.PwData; var creds = new SoundCloudCredentials("78fd88dde7ebf8fdcad08106f6d56ab6", "ef6b3dbe724eff1d03298c2e787a69bd"); if (username != null && password != null) { creds = new SoundCloudCredentials("78fd88dde7ebf8fdcad08106f6d56ab6", "ef6b3dbe724eff1d03298c2e787a69bd", username, _encryption.DecryptString(Instance.Configuration.PwData)); } SoundCloudClient = new SoundCloudClient(creds); }