Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • David Peck 687 posts 1863 karma points c-trib
    Mar 29, 2021 @ 10:11
    David Peck
    0

    Email pipeline issues

    Related to Github issue #287

    I can't get the pipeline workaround to work.

    composition.WithSendEmailPipeline().Append<AddContactFormReplyToEmailTask>();
    

    Also

    public class AddContactFormReplyToEmailTask : PipelineTaskWithTypedArgsBase<EmailSendPipelineArgs, EmailContext>
    {
        private readonly ILogger _logger;
    
        public AddContactFormReplyToEmailTask(ILogger logger)
        {
            this._logger = logger;
        }
    
        public override PipelineResult<EmailContext> Execute(EmailSendPipelineArgs args)
        {
            if (args?.Model?.Model is ContactFormDto contactFormModel)
            {
                var emailAddress = contactFormModel.EmailAddress?.Trim() ?? string.Empty;
                if (emailAddress.Length > 0)
                {
                    args.EmailContext.MailMessage.Body += "<strong>Edited</strong>";
                    try
                    {
                        args.EmailContext.MailMessage.ReplyToList.Add(new MailAddress(emailAddress, $"{contactFormModel.FirstName} {contactFormModel.LastName}"));
                    }
                    catch (FormatException)
                    {
                        this._logger.Debug<AddContactFormReplyToEmailTask>("Format exception thrown when adding reply to address");
                    }
                }
            }
    
            return this.Ok(args.EmailContext);
        }
    }
    

    The relevant lines are hit in the debugger, but the mail message appears unedited. Is this my implementation or a bug?

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Mar 29, 2021 @ 10:24
    Matt Brailsford
    1

    Hi David,

    I think it's because you are just appending the pipeline task, which means it'll get added on the end of the pipeline, but the last task in the default email pipeline is a "send email" task, so your task will be added and thus running after this one, and so is running too late.

    You'll probably need to register it like this instead.

    composition.WithSendEmailPipeline()
        .InsertBefore<SendSmtpEmailTask, AddContactFormReplyToEmailTask>();
    

    Matt

  • David Peck 687 posts 1863 karma points c-trib
    Mar 29, 2021 @ 11:13
    David Peck
    0

    Exactly that. Many thanks.

    Just in case you have more fools developing, it may be worth updating the docs here. While they are accurate, I hadn't appreciated that SendSmtpEmailTask was a pipeline step itself and therefore the order was pertinent.

Please Sign in or register to post replies

Write your reply to:

Draft