定時傳送郵件

2022-03-05 23:19:55 字數 1638 閱讀 7160

香港那邊的公司的erp糸統是bs模式,由於對方公司伺服器環境條件與解決方案要簡單的限制,我和我師傅決定用第三種方法。在程式設計之前,先介紹一下global.asax檔案裡的幾個方法。

protected

void

protected void

下面是具體的做法:

**protected

void

=new

timer(60000

);//

設計時間間隔,如果乙個小時執行一次就改為3600000 ,這裡一分鐘呼叫一次

t.elapsed 

+=new

elapsedeventhandler(t_elapsed);

t.autoreset 

=true

;t.enabled 

=true;}

private

void

t_elapsed(

object

sender, elapsedeventargs e)

intsendtime_hour ="

sendtime

"].tostring());//假如是下午17:00分傳送

intnow_hour 

=convert.toint32(datetime.now.hour.tostring());

intnow_minute 

=convert.toint32(datetime.now.minute.tostring());

intabsolute =1

;//差距值,單位為分鐘

if(((now_hour 

==sendtime_hour -1

) &&

(now_minute 

>=60-

absolute)) 

||((now_hour 

==sendtime_hour) 

&&(now_minute 

<=

absolute)))    //即在如果時間判斷是落在16:59分至17:01分之間,那麼就會呼叫下面的郵件傳送方法

catch

(exception ex)}}

如果一定要確精到分,可以設定相距時間為秒級,以及設定定時器的時間間隔為秒級,比如一秒呼叫一次t_elapsed,但必須符合的一件條件是:定時器的時間間隔<2*absolute,absolute為差距值,見上面黃色背景的定義,具體多少以客戶的要求為準,不滿足這個條件的話不能實現在規定的時間段內呼叫郵件傳送的方法。

解決方法:在iis6.0以上版本設定iis應用程式池的**時間,預設好像是20分鐘,可設定長一些,但不要太長,否則有可能出現**假死的現象。當晚再測試,可以正式傳送郵件!起碼到現在已經用了兩三個月,都能正常定時傳送郵件。iis5.0沒有應用程式池,可以在c:\windows\microsoft.net\framework\v2.0.50727\config\ machine.config裡面設定,具體設定可以參照:

3)新增、修改或刪除應用程式的 global.asax 檔案。

5)新增、修改或刪除配置檔案配置。

7)新增、修改或刪除應用程式的 web.config 檔案。

附應用程式生命週期概述:

附.net垃圾**機制 :

附sqlserver傳送郵件解決方法:

delphi郵件定時傳送

unit smtp inte ce uses windows,messages,sysutils,variants,classes,graphics,controls,forms,dialogs,stdctrls,idbasecomponent,idcomponent,idtcpconnection...

Java 定時傳送郵件

ublic class runmain 附件傳送執行緒 class mail extends thread else else else mail.send system.out.println time 附近已傳送完畢!if this.getid thread.currentthread geti...

vbs定時傳送郵件

用vbs寫個指令碼,然後用windows平台下的計畫任務來呼叫,每天定時 郵件.dim connstr,conn dim sql,rs,msg sub opendb connstr dsn 51tiao.com uid sa pwd if not isobject conn then set con...