2013-12-16 24 views
-1

當我在本地運行應用程序 - 基本上在IIS Express(以前稱爲開發服務器)上時,此工作正常。但是,如果我發佈到IIS,它不起作用。在兩臺不同的機器上嘗試了兩個不同的IIS。在IIS上運行時,我不知道如何獲取任何日誌信息。所有關於檢查是否每分鐘都有新記錄發送電子郵件。發送電子郵件與IIS Express(開發服務器)正常工作,但與IIS失敗

的Global.asax:

protected void Application_Start(object sender, EventArgs e) 
{ 
    System.Timers.Timer timer = new System.Timers.Timer(); 
    timer.Interval = 60000;  
    timer.AutoReset = true; 
    timer.Elapsed += new ElapsedEventHandler(NewCandidates); 
    timer.Enabled = true; 
} 

public void NewCandidates(object source, System.Timers.ElapsedEventArgs e) 
{ 
    SendEmail.MailSender mail = new MailSender(); 
    mail.EmailSender(); 
} 

EmailSender方法:

public void EmailSender() 
    { 
     Entities entity = new Entities(); 
     DateTime moment = DateTime.Now.AddMinutes(-1); 

     var ilan = from ilanRow in entity.IsIlan 
        where (ilanRow.Date >= moment) && (ilanRow.Yayinla==true) 
        from iOnay in entity.IlanOnay 
        where iOnay.IlanId == ilanRow.IsIlanId 
        from sirket in entity.KurumFirma 
        where sirket.KurumFirmaId==ilanRow.KurumFirmaId 
        select new { ilanRow, iOnay, sirket }; 

     List<IlanList> liste = new List<IlanList>(); 

     foreach (var itemilan in ilan) 
     { 
      liste.Add(new IlanList 
      { 
       KurumId  = itemilan.ilanRow.KurumFirmaId, 
       IlanId  = itemilan.ilanRow.IsIlanId, 
       SirketAdi = itemilan.sirket.Adi, 
       IlanAdi  = itemilan.ilanRow.Adi, 
       Il   = itemilan.ilanRow.Il, 
       IsAlan  = itemilan.ilanRow.IsAlan, 
       Date  = itemilan.ilanRow.Date, 
       Sonuc  = itemilan.iOnay.sonuc 
      }); 
     } 

     List<IlanOnayList> listeOnay = new List<IlanOnayList>(); 

     MailMessage message = new MailMessage(); 
     message.From = new MailAddress("[email protected]"); 
     message.To.Add(new MailAddress("[email protected]")); 
     message.Subject = "New Ones"; 
     string body = "<table style=\"border:1px solid gray; padding:5px;\"><th>Şirket Adı</th><th>İlan Adı</th><th>İl</th><th>İş Alanı</th><th>Tarih</th>"; 
     foreach (var item in liste) 
     { 
      body = body + 
       "<tr><td style=\"border:1px solid gray; padding:5px;\">" + item.SirketAdi + 
       "<td style=\"border:1px solid gray; padding:5px;\">" + item.IlanAdi + 
       "</td><td style=\"border:1px solid gray; padding:5px;\">" + item.Il + 
       "</td><td style=\"border:1px solid gray; padding:5px;\">" + item.IsAlan + 
       "</td><td style=\"border:1px solid gray; padding:5px;\">" + item.Tarih + 
       "</td></tr>"; 
     } 
     body = body + "</table><br />"; 
     message.Body = body; 
     message.IsBodyHtml = true; 
     SmtpClient client = new SmtpClient(); 
     foreach (var item in liste) 
     { 
      if (liste.Count > 0 && item.Sonuc != "var") 
      { 
       client.Send(message); 
       var onay = from i in entity.IlanOnay where i.IlanId == item.IlanId select i; 
       foreach (var itemonay in onay) 
       { 
        itemonay.sonuc = "var"; 
        entity.SaveChanges(); 
       } 
      } 
     } 
    } 

的Web.Config:

<system.net> 
<mailSettings> 
    <smtp from="[email protected]"> 
    <network host="auth.myhosting.com" port="587" userName="[email protected]" password="123456" defaultCredentials="false" /> 
    </smtp> 
</mailSettings> 

+0

'start'>'run'>'eventvwr'>'application events' – Abhitalks

+1

什麼是MailSender,你會如何發送電子郵件?我們需要查看一些實現細節和配置(如果有的話)? – Leo

+0

通過SMTP。在EmailSender方法裏面:MailMessage message = new MailMessage(); SmtpClient client = new SmtpClient(); client.Send(message); – Jude

回答

1

顯然,你需要瀏覽的網站一次,當它發佈給我IS。它正在工作!

相關問題