我正在尝试使用Quartz.net发送peroidic电子邮件,但没有成功。首先,下面的电子邮件代码部分经过验证可以正常工作,因为我打开了一个新项目来测试它。当我打开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);
}
}
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>
答案 0 :(得分:0)
好的发生在应该驻留在程序文件(x86)中的/Quartz.Net/Quartz.Server.exe.config中,我错过了connectionstring和mailsettings。希望它可以帮助别人。