Exemple #1
0
        public void Send(MailerConfig config, Notification notification)
        {
            var client = _smtpFactory.Create(config.Host, config.Port);

            client.Credentials = new NetworkCredential(config.UserName, config.Password);
            client.EnableSsl   = config.EnableSsl;

            using (var message = new MailMessage(config.From, config.To))
            {
                message.Subject = notification.Title;
                message.Body    = notification.Message;

                client.Send(message);
            }
        }
Exemple #2
0
        public JsonResult SendToMail(long userId, string email)
        {
            if (IdValidator.IsInvalid(userId) || string.IsNullOrWhiteSpace(email))
            {
                return(JsonResultHelper.Error());
            }

            string uniqueUserId = GetUserUniqueId();

            if (string.IsNullOrEmpty(uniqueUserId))
            {
                return(JsonResultHelper.Error());
            }

            string domain = WebSettingsConfig.Instance.Domain;

            //TODO: вынести в конфиг
            var mailerConfig = new MailerConfig {
                IsHtmlBody  = true,
                DisplayName = "Сайт " + domain
            };

            const string SUBJECT = "Ваш уникальный идентификатор";
            string       body    = string.Format("Здравствуйте, Уважаемый пользователь!<br />"
                                                 + "Ваш уникальный идентификатор на сайте {0}:<br /><b>{1}</b><br /><br />"
                                                 + "<span style='font-size:12px;'><b>" + Message + "</b></span><br />"
                                                 +
                                                 "<span style='font-size: 11px;'>Если Вы не указывали этот адрес почты на сайте {0}, то просто удалите это письмо.<br />" +
                                                 "Данное письмо не требует ответа.</span>",
                                                 domain, uniqueUserId);

            var  mailer    = new Mailer();
            bool isSuccess = mailer.SendMail(MailAddresses.SUPPORT, email, SUBJECT, body, mailerConfig);

            if (isSuccess)
            {
                var usersQuery = new UsersQuery();
                if (!usersQuery.UpdateEmail(userId, email))
                {
                    LoggerWrapper.LogTo(LoggerName.Errors).ErrorFormat(
                        "ProfileController.SendToMail для пользователя с идентификатором {0}, не смогли обновить адрес электронной почты на {1}",
                        userId, email);
                }
            }

            return(JsonResultHelper.Success(isSuccess));
        }
Exemple #3
0
        public static void RemoteMessage(LoggingSource loggingSource,
                                         LoggingType loggingType,
                                         string message,
                                         params object[] args)
        {
            string formattedMessage = string.Format(message, args);
            bool   isSuccess;

            if ((loggingSource & LoggingSource.Mail) == LoggingSource.Mail)
            {
                string subject      = loggingType + " логирование с сайта";
                var    mailerConfig = new MailerConfig {
                    IsHtmlBody   = false,
                    DisplayName  = subject,
                    SendToAdmins = true
                };

                var    mailer      = new Mailer.Mailer();
                string mailAddress = loggingType.HasFlag(LoggingType.Error) ? MailAddresses.EXCEPTIONS : MailAddresses.SUPPORT;
                isSuccess = mailer.SendMail(mailAddress, mailAddress, subject, formattedMessage, mailerConfig);

                if (!isSuccess)
                {
                    LogTo(LoggerName.Errors).ErrorFormat(
                        "LoggerWrapper.RemoteMessage не удалось отправить сообщение по почте: {0}",
                        formattedMessage);
                }
            }

            /*if ((loggingSource & LoggingSource.Db) == LoggingSource.Db) {
             *  isSuccess = _loggerQuery.Create(loggingType, formattedMessage);
             *
             *  if (!isSuccess) {
             *      LogTo(LoggerName.Errors).ErrorFormat(
             *          "LoggerWrapper.RemoteMessage не удалось записать сообщение в БД: {0}",
             *          formattedMessage);
             *  }
             * }*/
        }
Exemple #4
0
        public void TestConfig(MailerConfig config)
        {
            var notif = new Notification("Hadouken", "Test notification from Hadouken.");

            _mailSender.Send(config, notif);
        }
Exemple #5
0
 public void SetConfig(MailerConfig config)
 {
     _keyValueStore.Set("mailer.config", config);
 }