我正在使用 Quartz 做一个简单的邮件发送测试,如下所示,不知何故在跟踪日志中,我收到了这个错误:
12:42:00 [ServerScheduler_Worker-7] DEBUG HelloWorldQuartzDotNet.HelloWorldJob -
***
Failed: Value cannot be null.
Parameter name: address
***
我相信这与从我的 app.config 键值中提取值有关。有人可以请教我做错了什么吗?我可以确保电子邮件发送代码工作正常,因为我提取了电子邮件代码部分,并将其作为一个独立的新项目进行了尝试。
谢谢。
public void Execute(IJobExecutionContext context)
{
try
{
Log.DebugFormat("{0}****{0}Job {1} fired @ {2} next scheduled for {3}{0}***{0}",
Environment.NewLine,
context.JobDetail.Key,
context.FireTimeUtc.Value.ToString("r"),
context.NextFireTimeUtc.Value.ToString("r"));
MailMessage mail = new MailMessage();
mail.IsBodyHtml = true;
mail.From = new MailAddress(ConfigurationManager.AppSettings.Get("COMPANYEMAIL"),
ConfigurationManager.AppSettings.Get("COMPANYNAME"));
mail.To.Add("me1234@hotmail.com");
mail.Subject = "Daily Email";
string body = "";
string filePath =
HttpContext.Current.Server.MapPath("~/" + ConfigurationManager.AppSettings["EmailTemplates"] + "/");
if (File.Exists(filePath + "Test.htm"))
{
FileStream f1 = new FileStream(filePath + "Test.htm", FileMode.Open);
StreamReader sr = new StreamReader(f1);
body = sr.ReadToEnd();
body = body.Replace("<%UserName%>", "Mr Big");
f1.Close();
}
mail.Body = body;
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess |
DeliveryNotificationOptions.OnFailure;
var Th = new Thread(() => Email.Send(mail, 3, 3000, true));
Th.Start();
Log.DebugFormat("{0}***{0}Daily Email Sent!{0}***{0}", Environment.NewLine);
}
catch (Exception ex)
{
Log.DebugFormat("{0}***{0}Failed: {1}{0}***{0}", Environment.NewLine, ex.Message);
}
}
我的 app.config 的一部分:
<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"/>
<add key="USER_DEFAULTPHOTO_PATH" value="UserProfilePhoto/default.png" />
<add key="USER_PROFILEPHOTO_PATH" value="UserProfilePhoto" />
<add key="MAX_INBOX_COUNT" value="200" />
<add key="FAILONANYADDRESS" value="false" />
<add key="COMPANYEMAIL" value="coy1234@hotmail.com" />
<add key="COMPANYNAME" value="MyApp" />
<add key="EMAILTEMPLATES" value="EmailTemplates" />
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="coy1234@hotmail.com">
<network host="smtp.live.com" port="25" userName="coy1234@hotmail.com" password="123456789" />
</smtp>
</mailSettings>
</system.net>
</quartz>