네이트온 팀룸으로 메일 수신 확인
필요 모듈
node-libcurl, querystring, flat-file-db, yapople
안내
미완성입니다. 일단 수신은 되요.
소스
[code]
var Curl = require( 'node-libcurl' ).Curl;
var querystring = require('querystring');
var flatfile = require('flat-file-db');
var db = flatfile.sync('./tmp/my.db');
/*
db.put('test', 'zzz');
console.log(db.get('test'));
db.del('test')
*/
var Client = require('yapople').Client;
var client = new Client({
hostname: 'pop3.nate.com',
port: 995,
tls: true,
mailparser: true,
username: '아이디@호스트',
password: '비밀번호'
});
var Time = 5000; // 실행주기 (1000->1s)
var testInterval;
testInterval = setInterval(function(){
client.connect(function() {
client.retrieveAll(function(err, messages) {
messages.forEach(function(message) {
var nowDate = new Date();
var mailTime = message.date;
var last_time = db.get('last_time');
console.log(last_time, nowDate);
if(last_time != undefined) db.put('last_time', nowDate.getTime()); // 최초 실행시 이전 메일은 무시
if(mailTime.getTime() <= last_time) return; // 메일 수신 시간이 기록된 시간보다 작으면 실행 차단
db.put('last_time', mailTime.getTime()); // 기록 시간 갱신
// --- 이메일이 차단 상태인지 체크 ---
var MailCheck = db.get(message.from[0]['address']);
//db.del(message.from[0]['address']); // - 차단 해제
if(MailCheck != undefined) return;
//db.put(message.from[0]['address'], 'block'); // - 차단
/*
// --- 이미 수신된 메일인지 체크 ---
var messageDB = db.get(message.messageId);
//db.del(message.messageId); // 수신확인 삭제
if(messageDB != undefined) return;
//db.put(message.messageId, 'block'); // 수신확인 처리
*/
/*
console.log('======================');
console.log('from Email: '+message.from[0]['address']);
console.log('from Name: '+message.from[0]['name']);
console.log('messageId: '+message.messageId);
console.log('date: '+message.date);
console.log('subject: '+message.subject);
console.log(mailTime.getTime());
console.log(nowDate.getTime());
*/
var FullDate = mailTime.getFullYear()+'-'+mailTime.getMonth()+'-'+mailTime.getDate()+' '+mailTime.getHours()+':'+mailTime.getMinutes();
var msg = '['+message.from[0]['name']+' - '+message.from[0]['address']+'] '+FullDate+'\n'+message.subject;
var curl = new Curl();
// 네이트온으로 발송
curl.setOpt('URL', '웹훅주소');
curl.setOpt('FOLLOWLOCATION', true );
curl.setOpt(Curl.option.VERBOSE, true );
curl.setOpt('SSL_VERIFYHOST', 0);
curl.setOpt('SSL_VERIFYPEER', 0);
curl.setOpt(Curl.option.HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);
data = {'content' : msg};
data = querystring.stringify(data);
curl.setOpt(Curl.option.POSTFIELDS, data);
curl.perform();
curl.on('end', curl.close.bind( curl ) );
curl.on('error', curl.close.bind(curl));
});
client.quit(); // 커넥트 종료
})
});
},Time);
[/code]
댓글 1개
--- 중단된 사항 ---
수신거부
수신거부 해제
응용프로그램화
게시판 목록
개발자팁
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4946 | node.js | 6년 전 | 2609 | ||
| 4945 | node.js | 6년 전 | 2380 | ||
| 4944 | node.js | 6년 전 | 2520 | ||
| 4943 | node.js | 6년 전 | 2271 | ||
| 4942 | node.js | 6년 전 | 2247 | ||
| 4941 | node.js | 6년 전 | 2719 | ||
| 4940 | node.js | 6년 전 | 1867 | ||
| 4939 | node.js | 6년 전 | 1995 | ||
| 4938 | node.js | 6년 전 | 2459 | ||
| 4937 | node.js | 6년 전 | 2250 | ||
| 4936 | node.js | 6년 전 | 2320 | ||
| 4935 | node.js | 6년 전 | 2136 | ||
| 4934 | node.js | 6년 전 | 2441 | ||
| 4933 | node.js | 6년 전 | 2246 | ||
| 4932 | node.js | 6년 전 | 2686 | ||
| 4931 | node.js | 6년 전 | 2070 | ||
| 4930 | node.js | 6년 전 | 1998 | ||
| 4929 | node.js | 6년 전 | 8631 | ||
| 4928 | node.js | 6년 전 | 3749 | ||
| 4927 | node.js | 6년 전 | 2392 | ||
| 4926 | node.js | 6년 전 | 2504 | ||
| 4925 | node.js | 6년 전 | 2082 | ||
| 4924 | node.js | 6년 전 | 3374 | ||
| 4923 | node.js | 6년 전 | 2221 | ||
| 4922 | node.js | 6년 전 | 1989 | ||
| 4921 | node.js | 6년 전 | 2046 | ||
| 4920 | node.js | 6년 전 | 1764 | ||
| 4919 | node.js | 6년 전 | 2031 | ||
| 4918 | node.js | 6년 전 | 2177 | ||
| 4917 | node.js | 6년 전 | 2395 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기