Пример #1
0
        public void Deliver(int emailMessageId)
        {
            var entity = _entities.Query<EmailMessage>()
                .EagerLoad(x => x.EmailAddress)
                .ById(emailMessageId, false)
            ;

            // don't send the message if it has already been sent
            if (entity.SentOnUtc.HasValue) return;

            // don't sent the message if it is not supposed to be sent yet
            if (entity.SendOnUtc > DateTime.UtcNow) return;

            var from = new MailAddress(entity.From);
            var to = new MailAddress(entity.EmailAddress.Value);
            var mailMessage = new MailMessage(from, to)
            {
                Subject = entity.Subject,
                Body = entity.Body,
                IsBodyHtml = entity.IsBodyHtml,
            };

            var sendState = new SendEmailMessageState
            {
                EmailMessageId = emailMessageId,
            };
            _mail.Deliver(mailMessage, OnSendCompleted, sendState);
        }
Пример #2
0
        public void Deliver(int emailMessageId)
        {
            var entity = _entities.Query <EmailMessage>()
                         .EagerLoad(x => x.EmailAddress)
                         .ById(emailMessageId, false)
            ;

            // don't send the message if it has already been sent
            if (entity.SentOnUtc.HasValue)
            {
                return;
            }

            // don't sent the message if it is not supposed to be sent yet
            if (entity.SendOnUtc > DateTime.UtcNow)
            {
                return;
            }

            var from        = new MailAddress(entity.From);
            var to          = new MailAddress(entity.EmailAddress.Value);
            var mailMessage = new MailMessage(from, to)
            {
                Subject    = entity.Subject,
                Body       = entity.Body,
                IsBodyHtml = entity.IsBodyHtml,
            };

            var sendState = new SendEmailMessageState
            {
                EmailMessageId = emailMessageId,
            };

            _mail.Deliver(mailMessage, OnSendCompleted, sendState);
        }