Ejemplo n.º 1
0
        public void SendRegistrationAdminEmailAsync(User user)
        {
            var emailText = new StringBuilder();

            emailText.AppendLine("New user registered to sc2bm.com!");
            emailText.AppendLine();
            emailText.AppendLine(string.Format("Username: {0}", user.UserName));
            emailText.AppendLine();

            new Thread(() => _smtpService.Send("*****@*****.**", "SC2BM - New user registered!", emailText.ToString(), true)).Start();
        }
Ejemplo n.º 2
0
        public OperationResult <bool> ResetPasswordRequest(string email)
        {
            try
            {
                var membership = membershipRepository.Get(x => x.Email == email).FirstOrDefault();
                if (membership != null)
                {
                    membership.ResetPasswordToken  = securityService.GenerateRandomCode();
                    membership.TokenExpirationDate = DateTime.Now.AddMinutes(5);

                    membershipRepository.Update(membership);

                    MailMessage mailMessage = new MailMessage(ConfigurationManager.AppSettings["SmtpEmail"], membership.Email);
                    mailMessage.IsBodyHtml = true;
                    mailMessage.Priority   = MailPriority.High;
                    mailMessage.Subject    = "Recuperación de contraseña";
                    mailMessage.Body       = string.Format("Código de recuperación: <strong>{0}<strong>", membership.ResetPasswordToken);

                    var sendResult = smtpService.Send(mailMessage);
                    if (!sendResult)
                    {
                        return(OperationResult <bool> .CreateSuccessResult(false));
                    }


                    return(OperationResult <bool> .CreateSuccessResult(true));
                }

                return(OperationResult <bool> .CreateFailure("No fue posible recuperar la contraseña."));
            }
            catch (Exception e)
            {
                return(OperationResult <bool> .CreateFailure(e));
            }
        }
Ejemplo n.º 3
0
        public void NotifySubscribedUsers(DownloadItem item, List <string> subscribedUsersEmails)
        {
            if (subscribedUsersEmails.Count == 0)
            {
                return;
            }
            var email = new MailMessage
            {
                IsBodyHtml = true,
                Subject    = $"[New episode available] { item.MainFilename }",
                Body       = BuildNewEpisodeAvailableMailBody(item)
            };

            subscribedUsersEmails.ForEach(e => email.Bcc.Add(new MailAddress(e)));
            smtpService.Send(email);
        }
 private void SendToProvider(Guid providerId, string contentsString, Dictionary <Guid, string[]> providers)
 {
     try
     {
         var      body = string.Format("{0} <br /> {1}", Header, contentsString);
         string[] emails;
         if (providers.TryGetValue(providerId, out emails) && emails.Any(e => !string.IsNullOrWhiteSpace(e)))
         {
             _smtpService.Send(Subject, body, emails.Where(c => !string.IsNullOrWhiteSpace(c)).ToArray());
         }
         else
         {
             _logger.Error("Не найдена информация о email адресах провайдере {0}", providerId);
         }
     }
     catch (Exception ex)
     {
         _logger.Fatal("Не удалось отправить сообщение контент провайдеру{0}", providerId);
         _logger.Info(ex, ex.Message);
     }
 }
Ejemplo n.º 5
0
        public void Run()
        {
            Debugger.Break();

            Console.WriteLine("== Bestellungen ==");

            IOrderService orderService = services.GetService <IOrderService>();

            orderService.PlaceOrder("Wattestäbchen", 10);
            orderService.PlaceOrder("Taschentuch", 1);
            orderService.PlaceOrder("Ölfaß", 10);

            Console.WriteLine();

            // Unterschiedliche SMTP-Services nutzen, je nach Environment
            Console.WriteLine("== MockedSmtpService ==");
            ISmtpService mockedSmtpService = services.GetService <MockedSmtpService>();

            mockedSmtpService?.Send("*****@*****.**", "Wichtig!", "...");

            Console.WriteLine("== FastSmtpService ==");
            ISmtpService fastSmtpService = services.GetService <FastSmtpService>();

            fastSmtpService?.Send("*****@*****.**", "Wichtig!", "...");

            // Via Interface. Leider nein. ISmtpService ist nicht registiert
            Console.WriteLine("== ISmtpService ==");

            // Liefert NULL, wenn der Service nicht geliefert warden kann
            ISmtpService iSmtpService = services.GetService <ISmtpService>();

            iSmtpService?.Send("*****@*****.**", "Wichtig!", "...");

            // Wirft eine Exception (System.InvalidOperationException) statt NULL zuliefern
            iSmtpService = services.GetRequiredService <ISmtpService>();
            iSmtpService.Send("*****@*****.**", "Wichtig!", "...");

            // Diese Komponente hat eine fehlende Abhängigkeit => Exception (immer!)
            IUseMissing useMissing = services.GetService <IUseMissing>();

            // Scope erzeugen (via ASP.NET Core als Request)
            using (IServiceScope scope = services.CreateScope())
            {
                ISmtpService  smtpServiceScope  = scope.ServiceProvider.GetService <ISmtpService>();
                IOrderService orderServiceScope = services.GetService <IOrderService>();

                // ...
            }

            Debugger.Break();
        }
        public IOptionObject2015 Execute()
        {
            logger.Debug("Executing {command}.", nameof(SendEmailCommand));

            string      to          = "*****@*****.**";
            string      from        = "*****@*****.**";
            string      subject     = "Example Send Email Command";
            string      body        = @"This is our example email to demonstrate sending of emails from ScriptLink.";
            MailMessage mailMessage = new MailMessage(from, to)
            {
                IsBodyHtml = false,
                Subject    = subject,
                Body       = body
            };

            _smtpService.Send(mailMessage);
            _smtpService.Dispose();

            return(_optionObject.ToReturnOptionObject(ErrorCode.None, "Email sent."));
        }
Ejemplo n.º 7
0
        public OptionObject2015 Execute()
        {
            // Get Email Address
            string emailAddress = GetEmailAddress();

            logger.Debug("Attempting to send an email to {emailAddress}.", emailAddress);

            if (string.IsNullOrEmpty(emailAddress))
            {
                logger.Error("A valid email was not provided to {command}.", nameof(SendTestEmailCommand));
            }
            else
            {
                // Create MailMessage
                MailMessage mailMessage = GetMailMessage(emailAddress);

                // Send MailMessage
                _smtpService.Send(mailMessage);
                _smtpService.Dispose();
            }

            return(_optionObject2015.ToReturnOptionObject(ErrorCode.Informational, "SendTestEmailCommand executed."));
        }
Ejemplo n.º 8
0
 public void SendByMail(string email, SmtpServiceOptions options = null)
 {
     _smtpService.Send(email, _mailTemplate.Subject, _mailTemplate.Message, options);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Sends a mail.
 /// The 'from' value comes from the configuration file and can be overrided from options.
 /// </summary>
 ///
 /// <param name="to">
 /// To field.
 /// </param>
 ///
 /// <param name="subject">
 /// Mail subject.
 /// </param>
 ///
 /// <param name="message">
 /// Mail message.
 /// </param>
 ///
 /// <param name="options">
 /// Options (optional).
 /// </param>
 public void Send(string to, string subject, string message, SmtpServiceOptions options = null)
 {
     _smtpService.Send(to, subject, message, options);
 }