Esempio n. 1
0
        public static async Task SendAsync(string tenant, Uri baseUri, EmailViewModel model)
        {
            var processor = EmailProcessor.GetDefault(tenant);

            if (processor == null)
            {
                throw new EmailException(I18N.NoEmailProcessorDefined);
            }

            string attachmentPath = ExportHelper.Export(tenant, baseUri, "pdf", model.Html);

            attachmentPath = PathMapper.MapPath(attachmentPath);

            var email = new EmailQueue
            {
                AddedOn     = DateTimeOffset.UtcNow,
                SendOn      = DateTimeOffset.UtcNow,
                SendTo      = model.SendTo,
                FromName    = processor.Config.FromName,
                ReplyTo     = processor.Config.FromEmail,
                Subject     = model.Subject,
                Message     = model.Message,
                Attachments = attachmentPath
            };

            var manager = new MailQueueManager(tenant, email);

            await manager.AddAsync().ConfigureAwait(false);

            await manager.ProcessQueueAsync(processor, true).ConfigureAwait(false);
        }
Esempio n. 2
0
        private void ProcessEmailQueue()
        {
            MailQueueManager manager = new MailQueueManager();

            manager.Catalog = AppUsers.GetCurrentUserDB();

            ThreadPool.QueueUserWorkItem(async callback => { await manager.ProcessMailQueueAsync(); });
        }
Esempio n. 3
0
        public async Task <bool> RemindAsync(string tenant, ReminderMessage message)
        {
            await Task.Delay(0).ConfigureAwait(false);

            string sendTo   = message.Contact.EmailAddresses;
            string timezone = message.Contact.TimeZone.Or(message.Event.TimeZone);

            if (string.IsNullOrWhiteSpace(sendTo))
            {
                return(false);
            }

            int alarm = message.Event.Alarm ?? 0;

            if (alarm == 0)
            {
                return(false);
            }

            string template  = Configs.GetNotificationEmailTemplate(tenant);
            string eventDate = TimeZoneInfo.ConvertTime(DateTime.UtcNow.AddMinutes(alarm), TimeZoneInfo.FindSystemTimeZoneById(timezone)).Date.ToString("D");
            string startTime = TimeZoneInfo.ConvertTime(message.Event.StartsAt, TimeZoneInfo.FindSystemTimeZoneById(timezone)).ToString("t");
            string endTime   = TimeZoneInfo.ConvertTime(message.Event.EndsOn, TimeZoneInfo.FindSystemTimeZoneById(timezone)).ToString("t");

            template = template.Replace("{Name}", message.Event.Name);
            template = template.Replace("{StartTime}", startTime);
            template = template.Replace("{EndTime}", endTime);
            template = template.Replace("{Date}", eventDate);
            template = template.Replace("{Location}", message.Event.Location);
            template = template.Replace("{Note}", message.Event.Note);


            var processor = EmailProcessor.GetDefault(tenant);

            if (processor == null)
            {
                return(false);
            }

            var email = new EmailQueue
            {
                AddedOn     = DateTimeOffset.UtcNow,
                SendOn      = DateTimeOffset.UtcNow,
                SendTo      = sendTo,
                FromName    = processor.Config.FromName,
                ReplyTo     = processor.Config.FromEmail,
                ReplyToName = processor.Config.FromName,
                Subject     = string.Format(I18N.CalendarNotificationEmailSubject, message.Event.Name, startTime),
                Message     = template
            };

            var manager = new MailQueueManager(tenant, email);
            await manager.AddAsync().ConfigureAwait(false);

            await manager.ProcessQueueAsync(processor).ConfigureAwait(false);

            return(true);
        }
Esempio n. 4
0
        public async Task SendAsync()
        {
            string template = GetTemplate();
            string parsed   = ParseTemplate(template);
            string subject  = "Welcome to " + HttpContext.Current.Request.Url.Authority;
            string catalog  = AppUsers.GetCatalog();
            var    email    = this.GetEmail(this._user, subject, parsed);
            var    queue    = new MailQueueManager(catalog, email);

            queue.Add();
            await queue.ProcessMailQueueAsync(EmailProcessor.GetDefault());
        }
Esempio n. 5
0
        public static async Task <bool> SendAsync(string tenant, EmailViewModel model)
        {
            var processor = EmailProcessor.GetDefault(tenant);

            if (processor == null)
            {
                return(false);
            }

            foreach (var contactId in model.Contacts)
            {
                var contact = await DAL.Contacts.GetContactAsync(tenant, model.UserId, contactId).ConfigureAwait(false);

                if (string.IsNullOrWhiteSpace(contact?.EmailAddresses) || !contact.EmailAddresses.Split(',').Any())
                {
                    continue;
                }

                //Only select the first email address
                string emailAddress = contact.EmailAddresses.Split(',').Select(x => x.Trim()).FirstOrDefault(IsValidEmail);

                if (string.IsNullOrWhiteSpace(emailAddress))
                {
                    continue;
                }

                string message = model.Message;
                message = MessageParser.ParseMessage(message, contact);

                var email = new EmailQueue
                {
                    AddedOn     = DateTimeOffset.UtcNow,
                    SendOn      = DateTimeOffset.UtcNow,
                    SendTo      = emailAddress,
                    FromName    = processor.Config.FromName,
                    ReplyTo     = processor.Config.FromEmail,
                    ReplyToName = processor.Config.FromName,
                    Subject     = model.Subject,
                    Message     = message
                };

                var manager = new MailQueueManager(tenant, email);
                await manager.AddAsync().ConfigureAwait(false);

                await manager.ProcessQueueAsync(processor).ConfigureAwait(false);
            }

            return(true);
        }
Esempio n. 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");
            }
        }
Esempio n. 7
0
        public async Task SendAsync(string tenant)
        {
            string template = this.GetTemplate(tenant);
            string parsed   = this.ParseTemplate(template);
            string subject  = "Your Password Reset Link for " + HttpContext.Current.Request.Url.Authority;

            var processor = EmailProcessor.GetDefault(tenant);

            if (processor != null)
            {
                var email = this.GetEmail(processor, this._resetDetails, subject, parsed);

                var queue = new MailQueueManager(tenant, email);
                await queue.AddAsync().ConfigureAwait(false);

                await queue.ProcessMailQueueAsync(processor).ConfigureAwait(false);
            }
        }
Esempio n. 8
0
        public async Task SendAsync(string tenant)
        {
            string template = this.GetTemplate(tenant);
            string parsed   = this.ParseTemplate(template);
            string subject  = string.Format(I18N.WelcometToSite, HttpContext.Current.Request.Url.Authority);

            var processor = EmailProcessor.GetDefault(tenant);

            if (processor != null)
            {
                var email = this.GetEmail(processor, this._user, subject, parsed);

                var queue = new MailQueueManager(tenant, email);
                await queue.AddAsync().ConfigureAwait(false);

                await queue.ProcessQueueAsync(processor).ConfigureAwait(false);
            }
        }
Esempio n. 9
0
        public async Task SendAsync(string tenant)
        {
            string template = this.GetTemplate(tenant);
            string parsed   = this.ParseTemplate(this._context, template);
            string subject  = "Confirm Your Registration at " + this._context.Request.Url.Authority;

            var processor = EmailProcessor.GetDefault(tenant);

            if (processor != null)
            {
                var email = this.GetEmail(processor, this._registration, subject, parsed);

                var queue = new MailQueueManager(tenant, email);

                await queue.AddAsync().ConfigureAwait(false);

                await queue.ProcessMailQueueAsync(processor).ConfigureAwait(false);
            }
        }
Esempio n. 10
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.ProcessQueueAsync(processor).ConfigureAwait(false);
            }
        }
Esempio n. 11
0
        public async Task SendAsync()
        {
            string template = this.GetTemplate();
            string parsed   = this.ParseTemplate(template);
            string subject  = "Welcome to " + HttpContext.Current.Request.Url.Authority;
            string tenant   = AppUsers.GetTenant();
            var    email    = this.GetEmail(this._user, subject, parsed);

            var processor = EmailProcessor.GetDefault(tenant);

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

            var queue = new MailQueueManager(tenant, email);

            queue.Add();
            await queue.ProcessMailQueueAsync(processor);
        }
Esempio n. 12
0
        private void CreateEmail(long tranId, string partyCode, string token)
        {
            string sendTo = Parties.GetEmailAddress(AppUsers.GetCurrentUserDB(), partyCode);

            if (string.IsNullOrWhiteSpace(sendTo))
            {
                return;
            }

            string message    = ProcessEmailMessage(tranId, token);
            string attachment =
                HostingEnvironment.MapPath("/Resource/Documents/" + Titles.SalesQuotation + "-#" + tranId + ".pdf");

            string subject = string.Format(Labels.SalesQuotationEmailSubject, tranId,
                                           AppUsers.GetCurrent().View.OfficeName);

            MailQueueManager queue = new MailQueueManager(AppUsers.GetCurrentUserDB(), message, attachment, sendTo,
                                                          subject);

            queue.Add();
        }
Esempio n. 13
0
        public async Task SendAsync()
        {
            string template = this.GetTemplate();
            string parsed   = this.ParseTemplate(template);
            string subject  = "Your Password Reset Link for " + HttpContext.Current.Request.Url.Authority;

            string catalog = AppUsers.GetCatalog();
            var    email   = this.GetEmail(this._resetDetails, subject, parsed);

            var processor = EmailProcessor.GetDefault(catalog);

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

            var queue = new MailQueueManager(catalog, email);

            queue.Add();
            await queue.ProcessMailQueueAsync(processor);
        }
Esempio n. 14
0
        public async Task SendAsync(string tenant, Subscribe model)
        {
            try
            {
                var email   = this.GetEmail(tenant, model);
                var manager = new MailQueueManager(tenant, email);
                manager.Add();

                var processor = EmailProcessor.GetDefault(tenant);

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

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