电子邮件cron作业(asp.net)与Quartz.Net不工作 [英] Email cron job (asp.net) with Quartz.Net not working

查看:134
本文介绍了电子邮件cron作业(asp.net)与Quartz.Net不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图发送邮件期周期与Quartz.net但没有成功。首先,电子邮件code以下部分被验证为我打开了一个新的项目来测试它的工作。当我打开application.log,我可以看到Log.DebugFormat消息,并没有异常被逮住,但没有电子邮件被发送出去。任何建议?谢谢你。

 公共无效执行(IJobExecutionContext上下文)
        {
            尝试
            {
                Log.DebugFormat({0} **** {0}作业{1}解雇@ {2}接下来的安排{3} {0} ***的{0} {4}炒鱿鱼,
                                                                        Environment.NewLine,
                                                                        context.JobDetail.Key,
                                                                        context.FireTimeUtc.Value.ToString(R),
                                                                        context.NextFireTimeUtc.Value.ToString(R),
                                                                        詹姆士);                Log.DebugFormat({0} *** {0}的Hello World!{0} *** {0},Environment.NewLine);                    //尝试发送电子邮件
                    VAR邮件=新的电子邮件();
                    mail.IsBodyHtml = TRUE;
                    mail.MailAddresses =ong1980@hotmail.com;
                    mail.MailSubject =测试定时任务;                    变种MAILMESSAGE = mail.CreateMailMessage();
                    VAR TH =新的Thread(()=> Email.Send(MAILMESSAGE,6,3000,真正的));
                    Th.Start();
            }
            赶上(异常前)
            {
                Log.DebugFormat({0} *** {0}失败:{1} {0} *** {0},Environment.NewLine,ex.Message);
            }
        }

App.Config中:

 <?XML版本=1.0&GT?;
<结构>
  < configSections>
    <节名称=石英TYPE =System.Configuration.NameValueSectionHandler,
             系统,版本= 1.0.5000.0,文化=中立,
             公钥= b77a5c561934e089/>
  < / configSections>
  <石英>
    <添加键=quartz.scheduler.instanceNameVALUE =ServerScheduler/>
    <添加键=quartz.threadPool.typeVALUE =Quartz.Simpl.SimpleThreadPool,石英/>
    <添加键=quartz.threadPool.threadCountVALUE =10/>
    <添加键=quartz.threadPool.threadPriorityVALUE =2/>
    <添加键=quartz.jobStore.misfireThresholdVALUE =60000/>
    <添加键=quartz.jobStore.typeVALUE =Quartz.Simpl.RAMJobStore,石英/>
  < /石英>    <&启动GT;
        < supportedRuntime版本=V4.0SKU =.net框架,版本= V4.0/>
    < /启动>  < system.net>
    < mailSettings>
      < SMTP deliveryMethod =从=xxx@hotmail.com&GT网络;
        <网络主机=smtp.live.com端口=25的userName =xxx@hotmail.com密码=XXXXXXXXX/>
      < / SMTP>
    < / mailSettings>
  < /system.net>< /结构>


解决方案

确定发生了/Quartz.Net/Quartz.Server.exe.config应驻留在Program Files(x86)的里面,我错过了ConnectionString中和mailsettings。希望它可以成为别人的帮助。

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.

这篇关于电子邮件cron作业(asp.net)与Quartz.Net不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆