Exemple #1
0
        public async Task <Email> BuildEmailFromAsync <TMailable>(TMailable mailable, Action <Email> emailBuilder)
            where TMailable : Mailable
        {
            mailable.MailingOptions = _options;

            var email = new Email();

            _options.SetDefaultEmail(email);

            mailable.Build(email);

            emailBuilder?.Invoke(email);

            var validation = await new EmailValidator().ValidateAsync(email);

            if (validation.IsValid == false)
            {
                throw new ValidationException(validation.Errors);
            }

            // TODO: think about this part. email.Template is necessary only for
            // generating string with email's html. after, we don't need it anymore
            // so it should not be serialized by the queue engine
            if (email.Template != null)
            {
                var fullFile = GetFullFile(mailable, email.Template);

                var body = await _razorRenderer.RenderViewToStringAsync(fullFile, email.Template.Model);

                email.Body   = body;
                email.IsHtml = true;
            }

            return(email);
        }
Exemple #2
0
        public async Task <Email> BuildEmailFrom <TMailable>(TMailable mailable, Action <Email> emailBuilder) where TMailable : Mailable
        {
            mailable.MailingOptions = _options;

            var email = new Email();

            _options.SetDefaultEmail(email);

            mailable.Build(email);

            emailBuilder?.Invoke(email);

            if (email.Template != null)
            {
                var fullFile = GetFullFile(mailable, email.Template);

                var body = await _razorRenderer.RenderViewToStringAsync(fullFile, email.Template.Model);

                email.Body   = body;
                email.IsHtml = true;
            }

            return(email);
        }