public async Task<ActionResult> SendEmailAsync(ContactForm model)
 {
     model.Subject = "Contact Form : " + model.Subject;
     string catalog = AppUsers.GetCatalog();
     await new ContactUsEmail().SendAsync(catalog, model);
     Thread.Sleep(1000);
     return this.Json("OK");
 }
Example #2
0
        public async Task<ActionResult> SendEmailAsync(ContactForm model)
        {
            model.Subject = "Contact Form : " + model.Subject;

            await new ContactUsEmail().SendAsync(this.Tenant, model).ConfigureAwait(false);
            await Task.Delay(1000).ConfigureAwait(false);
            return this.Json("OK");
        }
Example #3
0
 private EmailQueue GetEmail(string catalog, ContactForm model)
 {
     return new EmailQueue
     {
         AddedOn = DateTime.Now,
         FromName = model.Name,
         ReplyTo = model.Email,
         Subject = model.Subject,
         Message = this.GetMessage(catalog, model),
         SendTo = this.GetEmails(catalog, model.ContactId)
     };
 }
Example #4
0
 private async Task<EmailQueue> GetEmailAsync(string tenant, ContactForm model)
 {
     return new EmailQueue
     {
         AddedOn = DateTimeOffset.UtcNow,
         FromName = model.Name,
         ReplyTo = model.Email,
         Subject = model.Subject,
         Message = this.GetMessage(tenant, model),
         SendTo = await this.GetEmailsAsync(tenant, model.ContactId).ConfigureAwait(false)
     };
 }
Example #5
0
        public async Task<ActionResult> SendEmailAsync(ContactForm model)
        {
            string token = this.Session[TokenKey].ToString();
            if (token != model.Token)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            model.Subject = "Contact Form : " + model.Subject;
            string catalog = AppUsers.GetCatalog();
            await new ContactUsEmail().SendAsync(catalog, model);
            return this.Json("OK");
        }
Example #6
0
        public async Task SendAsync(string catalog, ContactForm 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");
            }
        }
Example #7
0
        public async Task SendAsync(string tenant, ContactForm model)
        {
            var email = await this.GetEmailAsync(tenant, model).ConfigureAwait(false);
            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);                
            }
        }
Example #8
0
        public async Task SendAsync(string catalog, ContactForm 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");
            }
        }
Example #9
0
        private string GetMessage(string catalog, ContactForm model)
        {
            string fallback = model.Email + " wrote : <br/><br/>" + this.ConvertLines(model.Message);

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

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

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

            if (string.IsNullOrWhiteSpace(message))
            {
                return fallback;
            }

            message = message.Replace("{{Email}}", model.Email);
            message = message.Replace("{{Name}}", model.Name);
            message = message.Replace("{{Message}}", this.ConvertLines(model.Message));

            return message;
        }