简体   繁体   中英

Email cron job (asp.net) with Quartz.Net not working

I am trying to send peroidic emails with Quartz.net but with no success. Firstly, the email code portion below is verified to work as I opened a new project to test it out. When I opened the application.log, I can see the Log.DebugFormat messages and not exceptions was catched, however no email was being sent out. Any advice? Thanks.

public void Execute(IJobExecutionContext context)        
        {
            try
            {
                Log.DebugFormat("{0}****{0}Job {1} fired @ {2} next scheduled for {3}{0}***{0} Fired by {4}", 
                                                                        Environment.NewLine,
                                                                        context.JobDetail.Key,
                                                                        context.FireTimeUtc.Value.ToString("r"), 
                                                                        context.NextFireTimeUtc.Value.ToString("r"),
                                                                        "James");

                Log.DebugFormat("{0}***{0}Hello World!!!{0}***{0}", Environment.NewLine);

                    // Try send email
                    var mail = new Email();
                    mail.IsBodyHtml = true;
                    mail.MailAddresses = "ong1980@hotmail.com";
                    mail.MailSubject = "Test Cron Job";

                    var mailMessage = mail.CreateMailMessage();
                    var Th = new Thread(() => Email.Send(mailMessage, 6, 3000, true));
                    Th.Start();
            }
            catch (Exception ex)
            {
                Log.DebugFormat("{0}***{0}Failed: {1}{0}***{0}", Environment.NewLine, ex.Message);
            }
        }

App.Config:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="quartz" type="System.Configuration.NameValueSectionHandler, 
             System, Version=1.0.5000.0,Culture=neutral, 
             PublicKeyToken=b77a5c561934e089"/>
  </configSections>
  <quartz>
    <add key="quartz.scheduler.instanceName" value="ServerScheduler"/>
    <add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz"/>
    <add key="quartz.threadPool.threadCount" value="10"/>
    <add key="quartz.threadPool.threadPriority" value="2"/>
    <add key="quartz.jobStore.misfireThreshold" value="60000"/>
    <add key="quartz.jobStore.type" value="Quartz.Simpl.RAMJobStore, Quartz"/>
  </quartz>

    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    </startup>

  <system.net>
    <mailSettings>
      <smtp deliveryMethod="Network" from="xxx@hotmail.com">
        <network host="smtp.live.com" port="25" userName="xxx@hotmail.com"            password="xxxxxxxxx" />
      </smtp>
    </mailSettings>
  </system.net>

</configuration>

Ok happen that inside the /Quartz.Net/Quartz.Server.exe.config which should reside in the program files(x86), I miss out the connectionstring and mailsettings. Hope it can be a help for someone else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM