public async Task SendAsync(string catalog, Subscribe model)
        {
            try
            {
                var email = this.GetEmail(catalog, model);
                var manager = new MailQueueManager(catalog, email);
                manager.Add();

                await manager.ProcessMailQueueAsync(EmailProcessor.GetDefault());
            }
            catch
            {
                throw new HttpException(500, "Internal Server Error");
            }
        }
        private EmailQueue GetEmail(string catalog, Subscribe model)
        {
            var config = EmailProcessor.GetDefaultConfig(catalog);
            string domain = HttpContext.Current.Request.Url.Host;
            string subject = string.Format(CultureInfo.InvariantCulture, "You are now unsubscribed on {0}", domain);

            return new EmailQueue
            {
                AddedOn = DateTime.Now,
                FromName = config.FromName,
                ReplyTo = config.FromEmail,
                Subject = subject,
                Message = this.GetMessage(catalog, model),
                SendTo = model.EmailAddress
            };
        }
Esempio n. 3
0
        private EmailQueue GetEmail(string tenant, Subscribe model)
        {
            var config = EmailProcessor.GetDefaultConfig(tenant);
            string domain = HttpContext.Current.Request.Url.Host;
            string subject = string.Format(CultureInfo.InvariantCulture, "Thank you for subscribing to {0}", domain);

            return new EmailQueue
                   {
                       AddedOn = DateTimeOffset.UtcNow,
                       FromName = config?.FromName,
                       ReplyTo = config?.FromEmail,
                       Subject = subject,
                       Message = this.GetMessage(tenant, model),
                       SendTo = model.EmailAddress
                   };
        }
Esempio n. 4
0
        public async Task<ActionResult> RemoveAsync(Subscribe model)
        {
            if (!string.IsNullOrWhiteSpace(model.ConfirmEmailAddress))
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            if (await EmailSubscriptions.RemoveAsync(this.Tenant, model.EmailAddress).ConfigureAwait(false))
            {
                var email = new SubscriptionRemovedEmail();
                await email.SendAsync(this.Tenant, model).ConfigureAwait(false);
            }

            await Task.Delay(1000).ConfigureAwait(false);
            return this.Ok();
        }
        public async Task<ActionResult> RemoveAsync(Subscribe model)
        {
            if (!string.IsNullOrWhiteSpace(model.ConfirmEmailAddress))
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            string catalog = AppUsers.GetCatalog();

            if (EmailSubscriptions.Remove(catalog, model.EmailAddress))
            {
                var email = new SubscriptionRemovedEmail();
                await email.SendAsync(catalog, model);
            }

            Thread.Sleep(1000);
            return Json("OK");
        }
        private string GetMessage(string catalog, Subscribe model)
        {
            string siteUrl = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);
            string domain = HttpContext.Current.Request.Url.Host;

            string file = HostingEnvironment.MapPath(string.Format(CultureInfo.InvariantCulture, TemplatePath, catalog));

            if (file == null || !File.Exists(file))
            {
                return string.Empty;
            }

            string message = File.ReadAllText(file, Encoding.UTF8);

            message = message.Replace("{{Domain}}", domain);
            message = message.Replace("{{SiteUrl}}", siteUrl);
            message = message.Replace("{{Email}}", model.EmailAddress);

            return message;
        }
        public async Task SendAsync(string catalog, Subscribe model)
        {
            try
            {
                var email = this.GetEmail(catalog, model);
                var manager = new MailQueueManager(catalog, email);
                manager.Add();

                var processor = EmailProcessor.GetDefault(catalog);

                if (string.IsNullOrWhiteSpace(email.ReplyTo))
                {
                    email.ReplyTo = processor.Config.FromEmail;
                }

                await manager.ProcessMailQueueAsync(processor);
            }
            catch
            {
                throw new HttpException(500, "Internal Server Error");
            }
        }
Esempio n. 8
0
        public async Task SendAsync(string tenant, Subscribe model)
        {
            try
            {
                var email = this.GetEmail(tenant, model);
                var manager = new MailQueueManager(tenant, email);
                await manager.AddAsync().ConfigureAwait(false);

                var processor = EmailProcessor.GetDefault(tenant);
                if(processor != null)
                {
                    if (string.IsNullOrWhiteSpace(email.ReplyTo))
                    {
                        email.ReplyTo = processor.Config.FromEmail;
                    }

                    await manager.ProcessMailQueueAsync(processor).ConfigureAwait(false);                    
                }
            }
            catch
            {
                throw new HttpException(500, "Internal Server Error");
            }
        }