crossvertise / ActionMailerNext

Fork of ActionMailer.Net, A easy to use library to generate emails with razor views
MIT License
42 stars 24 forks source link

OnMailSending is never executed #36

Open jbreuer opened 7 years ago

jbreuer commented 7 years ago

I've overriden the OnMailSending method, but it's never hit. This is my controller:

public class EmailController : MailerBase
{
    public EmailResult BaseEmail(BaseEmailViewModel mail)
    {
        this.MailAttributes.From = new MailAddress(mail.MailFrom);
        this.MailAttributes.To.AddRange(mail.MailTo.Select(s => new MailAddress(s)));
        this.MailAttributes.Bcc.AddRange(mail.MailToBcc.Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => new MailAddress(s)));
        this.MailAttributes.Subject = mail.MailSubject;
        this.MailAttributes.MessageEncoding = new UTF8Encoding();
        return this.Email("BaseEmail", mail);
    }

    protected override void OnMailSending(MailSendingContext context)
    {
        //Cancel for testing.
        context.Cancel = true;

        base.OnMailSending(context);
    }
}

We send the email like this: new EmailController().BaseEmail(emailViewModel).Deliver();

Is there an example on how to implement OnMailSending ?