Base solution for your next web application
Open Closed

Recurring Email job using Hangfire #3638


User avatar
0
jcompagnon created

Hello,

Using ABP.Hangfire 2.1.3, I'm trying to create a recurring job to send a daily email. Following many of the suggestions from #2645, I have the following:

public override void PreInitialize()
        {
Configuration.BackgroundJobs.UseHangfire(configuration => configuration.GlobalConfiguration.UseSqlServerStorage("Default"));
            GlobalConfiguration.Configuration.UseActivator(new WindsorHangFireJobActivator());
}
public override void PostInitialize()
        {
            IDailyEmailTaskAppService dailyEmailTaskAppService = IocManager.Resolve<IDailyEmailTaskAppService>();
            RecurringJob.AddOrUpdate(() => dailyEmailTaskAppService.SendDailyEmail(), Cron.Daily);}
class DailyEmailTaskAppService : FirstASPNetZeroAppServiceBase, IDailyEmailTaskAppService
    {
        private readonly IEmailSender _emailSender;
        private readonly IOrganizationUnitAppService _organizationAppService;

        public DailyEmailTaskAppService(IEmailSender emailSender, IOrganizationUnitAppService organizationAppService)
        {
            _emailSender = emailSender;
            _organizationAppService = organizationAppService;
        }
        
[UnitOfWork]
        public virtual void SendDailyEmail()
        {
            using(CurrentUnitOfWork.DisableFilter(AbpDataFilters.MayHaveTenant))
            {
                _emailSender.SendAsync("[email protected]", "Test Email Subject", "Test Email Body", false);
            }
        }
    }

Unfortunately, I'm still getting the same error as the last from the linked post, namely

Could not load file or assembly 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

.

Note that I'm very new to boilerplate so not everything done may be best way of doing things.

Thanks in advance!


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @JCompagnon,

    Have you seen this topic #2645. It was a similar problem and I think same solution is going to work for you.

    Thanks.

  • User Avatar
    0
    jcompagnon created

    Thanks, that worked!

  • User Avatar
    0
    ismcagdas created
    Support Team

    Great :)