0

我正在尝试使用 Quartz.net 发送周期性电子邮件,但没有成功。首先,当我打开一个新项目进行测试时,验证了下面的电子邮件代码部分可以正常工作。当我打开 application.log 时,我可以看到 Log.DebugFormat 消息并且没有捕获到异常,但是没有发送电子邮件。有什么建议吗?谢谢。

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);
            }
        }

应用程序配置:

<?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>
4

1 回答 1

0

好吧,在应该驻留在程序文件(x86)中的 /Quartz.Net/Quartz.Server.exe.config 中,我错过了连接字符串和邮件设置。希望它可以对其他人有所帮助。

于 2013-11-11T03:38:18.087 回答