Inheritance: IEmailConfig
Exemplo n.º 1
0
        public async Task ProcessMailQueueAsync(IEmailProcessor processor)
        {
            IEnumerable<EmailQueue> queue = MailQueue.GetMailInQueue(this.Catalog).ToList();
            var config = new Config(this.Catalog);

            if (this.IsEnabled())
            {
                foreach (var mail in queue)
                {
                    var message = EmailHelper.GetMessage(config, mail);
                    var attachments = mail.Attachments?.Split(',').ToArray();

                    bool success = await processor.SendAsync(message, false, attachments);

                    if (!success)
                    {
                        continue;
                    }

                    mail.Delivered = true;
                    mail.DeliveredOn = DateTime.UtcNow;


                    MailQueue.SetSuccess(this.Catalog, mail.QueueId);
                }
            }
        }
Exemplo n.º 2
0
 public static ICredentials GetCredentials(Config config)
 {
     return new SmtpCredentials
            {
                Username = config.SmtpUsername,
                Password = config.SmtpUserPassword
            };
 }
Exemplo n.º 3
0
 public static SmtpHost GetSmtpHost(Config config)
 {
     return new SmtpHost
            {
                Address = config.SmtpHost,
                Port = config.SmtpPort,
                EnableSsl = config.EnableSsl,
                PickupDirectory = config.PickupDirectory
            };
 }
Exemplo n.º 4
0
        public void InitializeConfig(string catalog)
        {
            var config = new Config(catalog);
            var host = EmailHelper.GetSmtpHost(config);
            var credentials = EmailHelper.GetCredentials(config);

            this.Config = config;
            this.Host = host;
            this.Credentials = credentials;
            this.IsEnabled = config.Enabled;
        }
Exemplo n.º 5
0
        public static EmailMessage GetMessage(Config config, EmailQueue mail)
        {
            var message = new EmailMessage
                          {
                              FromName = mail.FromName,
                              FromEmail = mail.FromEmail,
                              ReplyToEmail = mail.ReplyTo,
                              ReplyToName = mail.ReplyToName,
                              Subject = mail.Subject,
                              SentTo = mail.SendTo,
                              Message = mail.Message,
                              Type = Type.Outward,
                              EventDateUtc = DateTimeOffset.UtcNow,
                              Status = Status.Unknown
                          };


            return message;
        }
Exemplo n.º 6
0
        public static EmailMessage GetMessage(Config config, EmailQueue mail)
        {
            var message = new EmailMessage
            {
                FromName = mail.FromName,
                FromEmail = mail.ReplyTo,
                Subject = mail.Subject,
                SentTo = mail.SendTo,
                Message = mail.Message,
                Type = Type.Outward,
                EventDateUtc = DateTime.UtcNow,
                Status = Status.Unknown
            };


            if (string.IsNullOrWhiteSpace(message.FromEmail))
            {
                message.FromName = config.FromName;
                message.FromEmail = config.FromEmail;
            }

            return message;
        }
Exemplo n.º 7
0
        public async Task AddAsync()
        {
            this.Processor = EmailProcessor.GetDefault(this.Database);

            if(!this.IsEnabled())
            {
                return;
            }

            var config = new Config(this.Database, this.Processor);

            this.Email.ReplyTo = this.Email.ReplyTo.Or("");
            this.Email.ReplyToName = this.Email.ReplyToName.Or("");

            if(string.IsNullOrWhiteSpace(this.Email.FromName))
            {
                this.Email.FromName = config.FromName;
            }

            if(string.IsNullOrWhiteSpace(this.Email.FromEmail))
            {
                this.Email.FromEmail = config.FromEmail;
            }

            var sysConfig = MessagingConfig.Get(this.Database);

            if(sysConfig.TestMode)
            {
                this.Email.IsTest = true;
            }

            if(this.IsValidEmail(this.Email.FromEmail) &&
               this.IsValidEmail(this.Email.SendTo))
            {
                await MailQueue.AddToQueueAsync(this.Database, this.Email).ConfigureAwait(false);
            }
        }
Exemplo n.º 8
0
        public async Task ProcessMailQueueAsync(IEmailProcessor processor)
        {
            var queue = await MailQueue.GetMailInQueueAsync(this.Database).ConfigureAwait(false);
            var config = new Config(this.Database, this.Processor);

            if(this.IsEnabled())
            {
                foreach(var mail in queue)
                {
                    var message = EmailHelper.GetMessage(config, mail);
                    var attachments = mail.Attachments?.Split(',').ToArray();

                    bool success = await processor.SendAsync(message, false, attachments).ConfigureAwait(false);

                    if(!success)
                    {
                        continue;
                    }

                    mail.Delivered = true;
                    mail.DeliveredOn = DateTimeOffset.UtcNow;


                    await MailQueue.SetSuccessAsync(this.Database, mail.QueueId).ConfigureAwait(false);
                }
            }
        }