而不是使Chrome的插件,我要麼使窗口標題眨眼或使用HTML5通知。創建一個簡單的頁面,用於輪詢IMAP Gmail中的新郵件,並將gmail包含在一個大型的iFrame中。如果找到新消息,您的外部窗口可以發出通知。
HTML5通知:http://www.html5rocks.com/en/tutorials/notifications/quick/
閃爍標題(從this通過):
var newMailBlinker = (function() {
var oldTitle = document.title,
msg = 'New Mail!',
timeoutId,
blink = function() {
document.title = document.title == msg ? ' ' : msg;
},
clear = function() {
clearInterval(timeoutId);
document.title = oldTitle;
window.onmousemove = null;
timeoutId = null;
};
return function() {
if (!timeoutId) {
timeoutId = setInterval(blink, 1000);
window.onmousemove = clear;
}
};
}());
PHP投票Gmail的IMAP(從this通過):
$t1=time();//mark time in
$tt=$t1+(60*1);//total time = t1 + n seconds
do{
if(isset($t2)) unset($t2);//clean it at every loop cicle
$t2=time();//mark time
if(imap_num_msg($imap)!=0){//if there is any message (in the inbox)
$mc=imap_check($imap);//messages check
//var_dump($mc); die;//vardump it to see all the data it is possible to get with imap_check() and them customize it for yourself
echo 'New messages available';
}else echo 'No new messagens';
sleep(rand(7,13));//Give Google server a breack
if([email protected]_ping($imap)){//if the connection is not up
//start the imap connection the normal way like you did at first
}
}while($tt>$t2);//if the total time was not achivied yet, get back to the beginning of the loop
jQuery的AJAX查詢到您的IMAP腳本(從this通過):
// make the AJAX request
function ajax_request() {
$.ajax({
url: '/path/to/gmail/imap/checkMessages.php',
dataType: 'json',
error: function(xhr_data) {
// terminate the script
},
success: function(xhr_data) {
console.log(xhr_data);
if (xhr_data.status == 'No new messages') {
setTimeout(function() { ajax_request(); }, 15000); // wait 15 seconds than call ajax request again
} else {
newMailBlinker(); // blink the title here for new messages
}
}
contentType: 'application/json'
});
}
顯然,你不會使用jQuery和PHP輪詢。選擇一個進行投票。我建議讓客戶端進行輪詢,並在每個連接上對PHP進行一次IMAP檢查。這就是說,這些片段應該讓你開始:)
所有客戶......你的意思是所有的服務器? GMail,Hotmail,Yahoo和其他基於Web的電子郵件服務,以及Pop/Imap服務器也是如此? – ixe013 2013-03-18 19:11:06
@ ixe013我的意思是任何客戶,我不關心我使用哪一個。答案可能是thunderbird的一些特定附件。它不需要用於所有電子郵件服務。但它確實需要使用Windows和Pop/Imap。 – dezman 2013-03-18 19:32:29
爲什麼有人想要這樣做呢?如果你真的設法做到這一點,準備好讓自己精力充沛的用戶收到無數的仇恨郵件。 – HerrSerker 2013-03-21 15:10:54