Ejemplo n.º 1
0
        private void SendNewsletter(NewletterSettings newletterSettings, string html, bool testEmail = false, string subject = "New Content on Plex!")
        {
            Log.Debug("Entering SendNewsletter");
            var settings = EmailSettings.GetSettings();

            if (!settings.Enabled || string.IsNullOrEmpty(settings.EmailHost))
            {
                return;
            }

            var body = new BodyBuilder {
                HtmlBody = html, TextBody = "This email is only available on devices that support HTML."
            };

            var message = new MimeMessage
            {
                Body    = body.ToMessageBody(),
                Subject = subject
            };

            Log.Debug("Created Plain/HTML MIME body");

            if (!testEmail)
            {
                var users = UserHelper.GetUsersWithFeature(Features.Newsletter);
                if (users != null)
                {
                    foreach (var user in users)
                    {
                        if (!string.IsNullOrEmpty(user.EmailAddress))
                        {
                            message.Bcc.Add(new MailboxAddress(user.Username, user.EmailAddress));
                        }
                    }
                }

                if (newletterSettings.CustomUsersEmailAddresses != null &&
                    newletterSettings.CustomUsersEmailAddresses.Any())
                {
                    foreach (var user in newletterSettings.CustomUsersEmailAddresses)
                    {
                        if (!string.IsNullOrEmpty(user))
                        {
                            message.Bcc.Add(new MailboxAddress(user, user));
                        }
                    }
                }
            }

            message.Bcc.Add(new MailboxAddress(settings.EmailUsername, settings.RecipientEmail)); // Include the admin

            message.From.Add(new MailboxAddress(settings.EmailUsername, settings.EmailSender));
            SendMail(settings, message);
        }
Ejemplo n.º 2
0
        private void SendMassEmail(string html, string subject, bool testEmail)
        {
            var settings = EmailSettings.GetSettings();

            if (!settings.Enabled || string.IsNullOrEmpty(settings.EmailHost))
            {
                return;
            }

            var body = new BodyBuilder {
                HtmlBody = html, TextBody = "This email is only available on devices that support HTML."
            };

            var message = new MimeMessage
            {
                Body    = body.ToMessageBody(),
                Subject = subject
            };

            Log.Debug("Created Plain/HTML MIME body");

            if (!testEmail)
            {
                var users = UserHelper.GetUsers(); // Get all users
                if (users != null)
                {
                    foreach (var user in users)
                    {
                        if (!string.IsNullOrEmpty(user.EmailAddress))
                        {
                            message.Bcc.Add(new MailboxAddress(user.Username, user.EmailAddress)); // BCC everyone
                        }
                    }
                }
            }
            message.Bcc.Add(new MailboxAddress(settings.EmailUsername, settings.RecipientEmail)); // Include the admin

            message.From.Add(new MailboxAddress(settings.EmailUsername, settings.EmailSender));
            SendMail(settings, message);
        }
Ejemplo n.º 3
0
        private void Send(NewletterSettings newletterSettings, string html, PlexSettings plexSettings, bool testEmail = false)
        {
            var settings = EmailSettings.GetSettings();

            if (!settings.Enabled || string.IsNullOrEmpty(settings.EmailHost))
            {
                return;
            }

            var body = new BodyBuilder {
                HtmlBody = html, TextBody = "This email is only available on devices that support HTML."
            };
            var message = new MimeMessage
            {
                Body    = body.ToMessageBody(),
                Subject = "New Content on Plex!",
            };

            if (!testEmail)
            {
                if (newletterSettings.SendToPlexUsers)
                {
                    var users = Api.GetUsers(plexSettings.PlexAuthToken);
                    foreach (var user in users.User)
                    {
                        message.Bcc.Add(new MailboxAddress(user.Username, user.Email));
                    }
                }

                if (newletterSettings.CustomUsersEmailAddresses.Any())
                {
                    foreach (var user in newletterSettings.CustomUsersEmailAddresses)
                    {
                        message.Bcc.Add(new MailboxAddress(user, user));
                    }
                }
            }
            message.Bcc.Add(new MailboxAddress(settings.EmailUsername, settings.RecipientEmail)); // Include the admin

            message.From.Add(new MailboxAddress(settings.EmailUsername, settings.EmailSender));
            try
            {
                using (var client = new SmtpClient())
                {
                    client.Connect(settings.EmailHost, settings.EmailPort); // 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.EmailUsername, settings.EmailPassword);
                    }
                    Log.Info("sending message to {0} \r\n from: {1}\r\n Are we authenticated: {2}", message.To, message.From, client.IsAuthenticated);
                    client.Send(message);
                    client.Disconnect(true);
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Ejemplo n.º 4
0
 public EmailSender( )
 {
     settings = EmailSettings.GetSettings();
 }