實現Email佇列

2021-08-29 14:42:37 字數 1655 閱讀 1973

rails部署環境下使用lighttpd程序實時傳送email比較耗時間,對於要求不太緊急的email,可以暫存在email佇列裡,利用linux的crontab定時讀取傳送

1,加一張表email_queue:

[code]

class createemailqueues < activerecord::migration

def self.up

create_table :email_queues do |t|

t.string :subject

t.text :content

t.string :recipient

t.timestamps

endend

def self.down

drop_table :email_queues

endend

[/code]

需要傳送email時就向該錶插資料即可

2,emailqueue

[code]

class emailqueue < activerecord::base

def self.send_all_email_in_queue

emailqueue.find(:all, :order => "created_at asc").each do |email|

exceptionnotifier.deliver_sys_email(email.recipient, email.subject, email.content)

email.destroy

endend

end[/code]

3,寫乙個send_sys_email_job.rb檔案

[code]

env['rails_env'] = 'production'

require file.dirname(__file__)+'/config/environment'

emailqueue.send_all_email_in_queue

[/code]

4,寫乙個send_sys_email.sh檔案

這裡有陷阱,呼叫send_sys_email_job.rb檔案時必須寫全絕對路徑,因為crontab裡沒有環境變數

這樣就會每間隔10分鐘檢查一遍email佇列裡有沒有郵件並傳送

使用aspx實現傳送email

using system using system.data using system.configuration using system.collections using system.web using system.web.security using system.web.ui usin...

C 的E mail傳送簡單實現

sendeeail.aspx page language c autoeventwireup true codefile sendeeail.aspx.cs inherits web test sendeeail sendeeail.aspx.cs using system using system...

python學習筆記 實現收發Email

關於email的基礎知識就不說,直接進入python主題。一 傳送email 1 連線到郵件伺服器 2 登陸 如果需要的話 3 發出服務請求 比如傳送 4 退出 在smtp中我們主要用到的方法是 sendmail from,to,msg mopts,ropts 是把msg從from發給to,esmt...